JScrollpane最小化后失去尺寸 [英] JScrollpane loses size after minimize
问题描述
由于某种原因,在最小化窗口然后将其还原时,jscrollpane会以某种方式弄乱布局.
For some reason the jscrollpane somehow messes up the layout when the window is minimized and then restored.
请注意,如果文本区域中的文本不超过文本区域的大小(即,如果它没有使垂直滚动条出现),则不会发生这种情况.
Note that this is not happening if the text in the text area is not longer than the size of the text area (i.e. if it doesnt make a vertical scroll bar appear).
谁能看到这是怎么回事?
Can anyone see what's wrong with it?
我的下面的代码:
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);
首次启动应用程序时
When first launching the app
当文本长于文本区域高度时
When text longer than textarea height
还原后
推荐答案
对JScrollPane
的属性使用c.fill = GridBagConstraints.BOTH;
和weightx
和weighty
属性.会有所帮助.
Use c.fill = GridBagConstraints.BOTH;
with weightx
and weighty
properties for your JScrollPane
's. It will helps.
这篇关于JScrollpane最小化后失去尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!