Solved

Stopping the stretchiness of JTextAreas and JTables in a GridBagLayout

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java JRE greater than 1.6 5 62
more than one jdk and one jre 1 41
Error in @AspectJ Based AOP with Spring 2 13
jboss wildfly 10.1 10 89
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

770 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