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


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

Re: JTable, JScrollPane and empty space

From "A. W. Dunstan" <no@spam.thanks>
Organization OptiMetrics, Inc.
Date 2012-01-12 11:16 -0500
Subject Re: JTable, JScrollPane and empty space
Newsgroups comp.lang.java.gui
References <IdydnSRiIqV1LpHSnZ2dnUVZ_v2dnZ2d@megapath.net> <jej0hf$h35$1@dont-email.me> <o5ednZh5q8RBBZDSnZ2dnUVZ_omdnZ2d@megapath.net> <jektof$8dl$1@dont-email.me>
Followup-To comp.lang.java.gui
Message-ID <G6OdnZD1D6n3mpLSnZ2dnUVZ_j-dnZ2d@megapath.net> (permalink)

Followups directed to: comp.lang.java.gui

Show all headers | View raw


Thanks for looking - I'll give those a try.

The 'full-sized' version of this has a grid of several different components, 
used for entering parameters that will then be fed to an engineering 
simulation package. The 1st column (not shown in my sample code) is either 
empty or a checkbox, the 2nd is a label (tells the user what value they're 
entering and it's units), the 3rd column is the value they'll enter.  The 
JTables are for enumerated values; I use JSpinners for scalar values, and a 
custom component for when the user wants to run the simulation over a range 
of values (height of 20 meters vs height of {10, 20, 30, 40, 50} meters).  
The checkbox lets the user switch between scalar and range-of-values.

So the underlying problem is pretty much grid oriented, which led me to 
GridBagLayout initially.  GridLayout wants to make all the rows the same 
height & all the columns the same width, but my rows are of varying heights 
(ditto the columns).  I didn't think nested BoxLayouts would keep the rows 
_and_ columns lined up.  GroupLayout is a possibility.

thanks again!


 wrote:

> 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.

-- 
Al Dunstan, Software Engineer
OptiMetrics, Inc.
3115 Professional Drive
Ann Arbor, MI  48104-5131

"There are two ways of constructing a software design.  One way is to
make it so simple that there are obviously no deficiencies.  And the
other way is to make it so complicated that there are no obvious
deficiencies."
            - C. A. R. Hoare

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