Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JTextArea wont shrink

849521Mar 22 2011 — edited Mar 23 2011
I 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!
This post has been answered by User_64CKJ on Mar 23 2011
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 20 2011
Added on Mar 22 2011
11 comments
967 views