JTextArea wont shrink
849521Mar 22 2011 — edited Mar 23 2011I am trying to resize a JTextArea based on the parent window size. The text area is inside a JPanel, with a "null" layout manager. The JPanal has a componentResized method. It works fine when enlarging the text area. It just won't shrink.
The essence of the code in componentResized is:
JTextArea comp = (JTextArea)getComponent (i);
comp.setColumns (numCols);
Dimension newSize = comp.getPreferredSize();
comp.setBounds (0, topOfControl, newSize.width, newSize.height);
Using System.out.prinln, I've watch numCols - it increases and decreases correctly. When enlarging, getPreferredSize returns correct values, too. But, when shrinking, getPreferredSize sticks at its peak value.
Is this a bug? Is there a reason for this behavior?
Thanks!