Solved

Stopping the stretchiness of JTextAreas and JTables in a GridBagLayout

Posted on 2002-07-11
3
714 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

In this post we will learn different types of Android Layout and some basics of an Android App.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to implement Singleton Design Pattern in Java.

726 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