出于某种原因,当窗口最小化然后恢复时,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);
首次启动应用时
当文字长于textarea高度时
恢复后
答案 0 :(得分:0)
对c.fill = GridBagConstraints.BOTH;
的{{1}}和weightx
属性使用weighty
。这会有所帮助。