Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #4925

Re: JTable, JScrollPane and empty space

From markspace <-@.>
Newsgroups comp.lang.java.gui
Subject Re: JTable, JScrollPane and empty space
Date 2012-01-11 13:08 -0800
Organization A noiseless patient Spider
Message-ID <jektof$8dl$1@dont-email.me> (permalink)
References <IdydnSRiIqV1LpHSnZ2dnUVZ_v2dnZ2d@megapath.net> <jej0hf$h35$1@dont-email.me> <o5ednZh5q8RBBZDSnZ2dnUVZ_omdnZ2d@megapath.net>

Show all headers | View raw


I think I see what is going on.  I haven't double checked (modified the 
code to see if I'm right) but I think the issue is that you are adding 
components horizontally.  That is you add the label and the table in one 
row, and then you add another label and table for the next row.

That would allow the components to expand horizontally, if they needed 
to, but you want the tables to be able to expand vertically.  So the 
basic approach isn't going to work.

Take a look at this example from the tutorial.  Notice that button 4 
spans three cells in the grid bag layout and expands as needed:

<http://docs.oracle.com/javase/tutorial/uiswing/layout/gridbag.html>

What you want to do I think is take John's suggestion to use something 
like a Box or Flow layout.  Make a JPanel, and make it the last 
component (or only component) in the last column, like button 4 is the 
only component in the tutorial example.  Then instead of adding the 
tables to the grid layout directly, you'll add them to the panel.

That should let the panel expand up and down, like button 4 does, but 
also its layout (box or flow) will scoot the tables up and down as 
needed.  Grid bag is a *grid*, so it always tries to keep things lined 
up.  They can't flow up and down as needed on their own with just grid bag.

In general, this is an easy way to make layouts do what you want, 
composing layouts out of other, smaller layout components.  I find it 
easier to "see" what the components will do, rather than trying to find 
one big layout that does everything you want.

You might also be better served by other layouts, like Spring, but it's 
hard to say as I don't know your actual requirements.  Making the last 
component in your existing layout into a JPanel and adding the tables to 
that is the least intrusive change I can think of.

Back to comp.lang.java.gui | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

JTable, JScrollPane and empty space "A. W. Dunstan" <no@spam.thanks> - 2012-01-10 16:55 -0500
  Re: JTable, JScrollPane and empty space markspace <-@.> - 2012-01-10 19:43 -0800
    Re: JTable, JScrollPane and empty space "A. W. Dunstan" <no@spam.thanks> - 2012-01-11 09:12 -0500
      Re: JTable, JScrollPane and empty space markspace <-@.> - 2012-01-11 13:08 -0800
        Re: JTable, JScrollPane and empty space "A. W. Dunstan" <no@spam.thanks> - 2012-01-12 11:16 -0500
  Re: JTable, JScrollPane and empty space "John B. Matthews" <nospam@nospam.invalid> - 2012-01-11 07:47 -0500

csiph-web