Solved

Stopping the stretchiness of JTextAreas and JTables in a GridBagLayout

Posted on 2002-07-11
3
708 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
  • 2
3 Comments
 
LVL 7

Accepted Solution

by:
tomboshell earned 100 total points
Comment Utility
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
Comment Utility
Thanks for your information tomboshell - very helpful.  Please have the points.
0
 
LVL 7

Expert Comment

by:tomboshell
Comment Utility
Thank you, glad to be of help.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn how to implement Singleton Design Pattern in Java.

762 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now