I have a JTable inside a JScrollPanel in the CENTER of a Panel with a
BorderLayout (at the EAST there are some buttons, and the panel is
inside some other panel/box).
How can I do to get this scollpanel/table combo to fit all the
available space in the panel, besides that taken up by the buttons?
I found the call setPreferredScrollableViewportSize() can be used to do
this resizing, but I don't know from where this can be called, and how
one would compute this preferred size.
I find Swing to be a really primitive toolkit when it comes to layout.
Andrew Thompson - 27 Jun 2005 17:13 GMT
> I have a JTable inside a JScrollPanel in the CENTER of a Panel
A Panel, or a JPanel?
>..with a
> BorderLayout (at the EAST there are some buttons,
Button or JButton?
>..and the panel is inside some other panel/box).
..box? What is that?
> How can I do to get this scollpanel/table combo to fit all the
> available space in the panel, besides that taken up by the buttons?
[quoted text clipped - 4 lines]
>
> I find Swing to be a really primitive toolkit when it comes to layout.
Probably because you are not familiar with using it.
Writing X-plat GUI's relies on logical layouts, and using
logic to layout a GUI (as opposed to 'shove it there')
often represents a significant learning curve for
anybody starting with them.
If you have not already done them, I strongly recommend
"Using Layout Managers" from the Java Tutorial.
<http://java.sun.com/docs/books/tutorial/uiswing/layout/using.html>
Where is your code?

Signature
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane
matomira@acm.org - 27 Jun 2005 21:43 GMT
> > I have a JTable inside a JScrollPanel in the CENTER of a Panel
>
> A Panel, or a JPanel?
JPanel
> >..with a
> > BorderLayout (at the EAST there are some buttons,
>
> Button or JButton?
JButton
> >..and the panel is inside some other panel/box).
>
> ..box? What is that?
Box
> > How can I do to get this scollpanel/table combo to fit all the
> > available space in the panel, besides that taken up by the buttons?
[quoted text clipped - 14 lines]
> "Using Layout Managers" from the Java Tutorial.
> <http://java.sun.com/docs/books/tutorial/uiswing/layout/using.html>
No. It's because I have used modern things like Garnet.
Thanks
Pete Barrett - 27 Jun 2005 18:40 GMT
>I have a JTable inside a JScrollPanel in the CENTER of a Panel with a
>BorderLayout (at the EAST there are some buttons, and the panel is
[quoted text clipped - 6 lines]
>this resizing, but I don't know from where this can be called, and how
>one would compute this preferred size.
Generally, I find it best to leave the resizing to the LayoutManager,
though occasionally it's necessary to use
x.setMaximumSize(x.getPreferredSize()) to stop something being resized
beyond what it needs. BorderLayout is supposed to (and I've found it
does) give the CENTER component all the room not taken up by the other
components. Where is the space you want it to expand into? Top,
bottom, east or west?
>I find Swing to be a really primitive toolkit when it comes to layout.
Pete Barrett
Christian Kaufhold - 27 Jun 2005 20:56 GMT
> I have a JTable inside a JScrollPanel in the CENTER of a Panel with a
> BorderLayout (at the EAST there are some buttons, and the panel is
> inside some other panel/box).
>
> How can I do to get this scollpanel/table combo to fit all the
> available space in the panel, besides that taken up by the buttons?
In BorderLayout the center component gets all the remaining space. Another
layout higher in the hierarchy must be the culprit. Please post a compilable
example.
Christian
matomira@acm.org - 27 Jun 2005 21:46 GMT
I see questions everywhere on the web about how to fit a JTable to take
all available space, but no adequate answer.
A JList with JScrollPanel in the same place has no problem resizing
properly.
Christian Kaufhold - 27 Jun 2005 22:16 GMT
> I see questions everywhere on the web about how to fit a JTable to take
> all available space, but no adequate answer.
Then ask more specifically (code!). I cannot even determine whether your
problem is width or height.
> A JList with JScrollPanel in the same place has no problem resizing
> properly.
JTable JList (VERTICAL)
---------------------------------------------------------------------------------------------------------
minimum width sum of columns' /
preferred width sum of columns' | fixed, or maximum of renderers' preferred width
maximum width sum of columns' \
minimum/preferred/ \ sum of row heights rowCount * fixed height, or sum of renderer's
maximum width / preferred heights
preferredScrollable- explicitly set = preferred width
Viewport width (default: 450)
underflows width iff AUTO_RESIZE_OFF false
shrinks width to viewport unless AUTO_RESIZE_OFF false
preferredScrollable- explicitly set visibleRowCount (default: 8) [1]
Viewport height (default: 400) * (fixed cell size, or first cell's size)
underflows height true[2] false
shrinks height to viewport false false
[1] even probably wrongly implemented (if only one of fixedCellWidth/Height
is set, it is ignored).
[2] this has no effect on layout, only on whether the area below the cells
is filled by JTable background or JViewport background color.
Christian

Signature
And in short, I was afraid.
matomira@acm.org - 28 Jun 2005 10:15 GMT
I found the problem: the subclass of JPanel I made did not pass a
BorderLayout in the call to super(). So JTable does resize
automatically.
Thanks everybody.