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!

GridBagLayout and JTextArea.setLineWrap(true)

843806Jul 2 2007 — edited Jul 4 2007
Hi,

I am writing a GUI which uses a GridBagLayout as its layout manager.

It basically has two columns: the first fills 30%, and the second 70% the width of the JFrame.

This seems to work fine except that when I add a JTextArea and set it to line wrap, it expands the second column to fill as far as it can without overwriting and of the components in the first column.

before setLineWrap(true);
    col1                                            col2
|a                  |                                                          |
|b                  |                     JTexArea                             |
|c                  |                                                          |  
after:
    col1                                            col2
|a|                                                                            |
|b|                  JTextArea.setLineWrap(true)                              |
|c|                                                                            |  
I hope the above helps to explain the situation.

This only happens when I set the line wrapping. I want its fill setting to be BOTH, so that it fills its 70% of the width of JFrame. I have tried setting it to NONE, which shrinks it so it looks ridiculous. Setting its preferred and/or maximum size doesn't do anything, either.

Curiously, it doesn't do the same thing vertically, only horizontally.

Can anyone suggest why this is happening and how to fix it?

Cheers.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 1 2007
Added on Jul 2 2007
6 comments
160 views