2013-11-04 78 views
0

由於某種原因,當窗口最小化並且被恢復時,jscrollpane以某種方式混淆了佈局。JScrollpane在最小化後丟失大小

請注意,如果文本區域中的文本長度不超過文本區域的大小(即不顯示垂直滾動條),則不會發生這種情況。

任何人都可以看到它有什麼問題嗎?

我下面的代碼:

 super (new GridBagLayout()); 

     textField = new JTextArea(20,80); 
     textField.addKeyListener(null); 



     JScrollPane scrollPane1 = new JScrollPane(textField); 

     textArea = new JTextArea(20, 80); 
     textArea.setEditable(false);   
     JScrollPane scrollPane = new JScrollPane(textArea); 

     String[] dropValues = {"Format code","Add commas","Add quotes"}; 
     dropdown = new JComboBox(dropValues); 
     dropdown.setSelectedIndex(0); 


     myButton = new JButton("Do it babe!!!"); 
     myButton.addActionListener(this); 


     //Add Components to this panel. 
     GridBagConstraints c = new GridBagConstraints(); 
     c.gridwidth = GridBagConstraints.REMAINDER; 

//  c.fill = GridBagConstraints.HORIZONTAL; 
     add(dropdown, c); 



     c.anchor = GridBagConstraints.CENTER; 
//  c.fill = GridBagConstraints.BOTH; 
     c.weightx = 1.0; 
     c.weighty = 1.0; 
     add(scrollPane1, c); 
     add(myButton, c); 
     add(scrollPane, c); 

當第一次啓動應用程序 enter image description here

當比textarea的高度文本不再 enter image description here

恢復 enter image description here

+1

請將此代碼剪掉已經說明過的問題?,爲了更好地幫助您儘快發佈SSCCE,簡短,可運行,可編譯 – mKorbel

回答

0

使用後與weightxweighty屬性爲您的JScrollPane's。這將有所幫助。