aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes How to make JTable resize when app window is resized? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to make JTable resize when app window is resized?" Watch "How to make JTable resize when app window is resized?" New topic
Author

How to make JTable resize when app window is resized?

G Svensson
Greenhorn

Joined: Jul 26, 2009
Posts: 17
At the lower part of an swing app I have placed a JTable.
I need help in making the table size along with the window when a user maxamized or resized the window. I have tried


Here is the code



[Thumbnail for VisualSwingAppScreen02.jpg]

pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
The secret and key here are in the layout managers that you use. It appears that currently your GUI uses soley the NetBeans-generated GroupLayout. If so, you would do well to move away from that. Study the more human-friendly layout managers such as BorderLayout, GridLayout, BoxLayout, and FlowLayout as well as (later) GridBagLayout, and use them. Then you'll be able to have much more flexible GUIs. Please start here: Laying Out Components Within A Container

For instance, if you had your main app use a BorderLayout, you could place your JTable into a JScrollPane and place the scrollpane into the main app BorderLayout.CENTER. The components above the JTable could be placed into their own JPanel that uses, say BoxLayout, and then this top JPanel could be added to the main app BorderLayout.NORTH. The potential variations here are nearly endless.

Best of luck.
G Svensson
Greenhorn

Joined: Jul 26, 2009
Posts: 17
Thanks for your quick answer. You do have a really good point

I use Eclipse and a plugin called Visual Swing For Eclipse and it generates a GroupLayout for me. If I from here was to code by hand it would be very wise to use BorderLayout.

For this change of code to make a JTable expand along with app window i must ask: Is there a shorter way to fix this height-issue than swapping LayoutManager?

It is my guess that Visual Swing will not accept a change of LayoutManager.
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Surrven Surrvensson wrote:Thanks for your quick answer. You do have a really good point

You're welcome.

I use Eclipse and a plugin called Visual Swing For Eclipse and it generates a GroupLayout for me. If I from here was to code by hand it would be very wise to use BorderLayout. For this change of code to make a JTable expand along with app window i must ask: Is there a shorter way to fix this height-issue than swapping LayoutManager?

It's not a matter of short or long here. This is the correct way to do it I'm afraid, as without changing layout your scrollpane won't grow.

It is my guess that Visual Swing will not accept a change of LayoutManager.

I have no experience with Visual Swing, but I'm guessing that it will allow changing layout managers. That being said, I feel that coding your Swing by hand will give you greater freedom in creation of your GUIs and will may help you to learn Swing better. It's helped me!

An example of layouts:
G Svensson
Greenhorn

Joined: Jul 26, 2009
Posts: 17
You must have the Nobel Price if I am asked. Thank you so much.

I will definetly put some effort in understanding whats going on underneath the hood here.
Suns tutorial seems like a good place for me to hang out the next couple of hours.

Thanks again.

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36465
    
  15
And welcome to JavaRanch, Surrven Surrvenson.
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Surrven Surrvensson wrote:You must have the Nobel Price if I am asked. Thank you so much.

You're quite welcome. Best of luck!


I will definetly put some effort in understanding whats going on underneath the hood here.
Suns tutorial seems like a good place for me to hang out the next couple of hours.

You won't regret this.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to make JTable resize when app window is resized?
 
Similar Threads
Updating values in a jTable
problem in JTable
How to set size of columns in JTable
JTable In JTree
Displaying ArrayList data in a JTable