Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to make JTable resize when app window is resized?

 
G Svensson
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
VisualSwingAppScreen02.jpg
[Thumbnail for VisualSwingAppScreen02.jpg]
JTable is not extending down to the bottom of the window
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 50235
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to JavaRanch, Surrven Surrvenson.
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic