Solved

Stopping the stretchiness of JTextAreas and JTables in a GridBagLayout

Posted on 2002-07-11
3
718 Views
Last Modified: 2010-08-05
Wonder if someone could help me here please?

In the app I'm writing, I have a few dialogues that have GridBagLayouts on them.  Some of the controls in these GridBagLayouts are JTextAreas and JTables enclosed in JScrollPanes.

The first problem I have is with the JTable.  If the table is empty the GridBagLayout is displayed narrower than the dimensions I have assigned to it, but as soon as you add a row to the table, the JTable stretches wider to fill the unoccupied space which in turn pushes the other controls and panel to the right.

The second problem is with the JTextArea.  If I type into this control, and hold a key down, the text doesn't wrap to the next line, and once again the control stretches to fill the unoccupied space, thus sqaushing up all the controls to it's left.

Now I understand that by setting the weight of a column to 0 in a GridBagLayout constraint, the column doesn't stretch, but I need to specify a column percentage for the JTable and JTextArea controls because other columns exist within each GridBagLayout too.

Can someone help me here please?  Thanks
0
Comment
Question by:carlpaddick
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 7

Accepted Solution

by:
tomboshell earned 100 total points
ID: 7148461
for word wrapping : setWrapStyleWord(true)
and for line wrapping : setLineWrap(true)

I should think that you would need to set the preferred size for the component.  If you don't set it then the component will ask the UI for its size, if it is empty then its size is smaller.  Take a look at the JComponent JavaDoc for the method description for setPreferredSize(Dimension)

tom
0
 

Author Comment

by:carlpaddick
ID: 7148786
Thanks for your information tomboshell - very helpful.  Please have the points.
0
 
LVL 7

Expert Comment

by:tomboshell
ID: 7151664
Thank you, glad to be of help.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question