2013-03-08 140 views
0

我試圖把一個滾動文本區域,稱爲descriptionScroll。但是,滾動條不可見。我嘗試了很多方法,都以挫折而告終。滾動條不顯示在JTextArea

我錯過了什麼讓滾動條顯示?它應該出現在大的文本框旁邊的「描述」

這裏的右側是該相關一段代碼:

import javax.swing.JScrollPane; 
import javax.swing.JTextArea; 

protected JTextArea descriptionTextArea; 


protected JScrollPane descriptionScroll; 


String descriptionText = 
"Lot ID(s):\n" + 
"Wafer ID(s):\n" + 
"PSPT(Probe Ship Part Type):\n" + 
"Tester:\n" + 
"Tester Job Name:\n" + 
"PID (FPP, FPC):\n" + 
"Reprobe required before shipping lot? (Y/N)\n\n" + 
"Hold for (individual):\n" + 
"Hold for (group)\n" + 
"Expected release date\n" + 
"Hold Comments:\n\n" + 
"Shipping Information:\n" + 
"Special Instructions:\n"; 


public Constructor(){ 

descriptionTextArea = new JTextArea(descriptionText); 
descriptionScroll = new JScrollPane(descriptionTextArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); 
add(descriptionTextArea); 
add(descriptionScroll); 
pack(); 

setSize(790, 625); 
setDefaultCloseOperation(EXIT_ON_CLOSE); 
setLocationRelativeTo(null); 
setVisible(true); 


descriptionTextArea.setSize(650, 200); 
descriptionTextArea.setLocation(110, 228); 
descriptionTextArea.setLineWrap(true); 



} 

Missing scroll

+1

只需刪除該行'加(descriptionTextArea);' – 2013-03-08 22:04:01

回答

3

您要添加兩種JScrollPane中和的JTextArea到同一個容器。在JTextArea中加入JScrollPane中:

descriptionScroll.add(descriptionTextArea);

+0

這不會改變輸出,可惜... – 2013-03-08 21:21:57

+0

對不起。您不需要將JTextArea添加到JScrollPane。你需要將它設置爲viewportView。 descriptionScroll.setViewportView(descriptionTextArea); – 2013-03-08 21:34:03

+1

請修復您的帖子。 'descriptionScroll.add(descriptionTextArea);'不起作用。 'setViewPortView'或使用JScrollpane構造函數是要走的路。 – 2013-03-08 22:12:08