Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Stopping the stretchiness of JTextAreas and JTables in a GridBagLayout

Posted on 2002-07-11
3
Medium Priority
?
728 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 400 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

Independent Software Vendors: 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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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 learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses

604 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