I have nearly finished my Applet and I'm now left only to finalize the
layout. So far I've used a GridLayout(3, 1) but now want to change to
something else. I played around with a GridBagLayout() but I'm getting
unexpected resizing effects.
My applet consists of 3 areas in a single column, from top to bottom :
a) a tab pane
b) a JLabel wrapped in a ScrollPane used as message area
c) a scrollPane originally wrapped around a dummy Jlabel, and
later dynamically removed and replaced by a scrollPane wrapped
around a JTable
The first tab of the tab pane contains a ScrollPane wrapped around a
customized "myDisplay extends JPanel implements Scrollable", the other
tabs are just static control menus.
With the test grid layout the 3 areas a/b/c are (of course) of the same
vertical size.
The myDisplay in (a) is initialized to a 256x256 ramp image (which
appears to be definitely narrower than the applet width, and slightly
not tall enough to contain the image, so a vertical scroll bar appears.
Later I load images in it, which can be smaller or larger. They can
also be zoomed 2x, 3x, 4x etc. so they will soon become larger and
scroll bars appear as appropriate.
(b) is initialized to an empty area, messages appear in it and scroll
bar appears when it's full
(c) as I said is initialized to a "nothing loaded" message. As soon
as I load an image in (a) a table of "regions" is loaded in (c), which
can have more or less rows, therefore causing a scroll bar to appear or
not.
The only component for which a setPreferredSize is set is the myDisplay
inside the scroll pane in the first tab of (a).
In the test configuration (GridLayout(3, 1)) everything goes fine (the
three pieces a/b/c are never auto-resized, ... scroll bars in them
appear when appropriate ...
... but I'm NOT SATISFIED because the three pieces have the same height.
What I'd wish to achieve is 3 components of DIFFERENT height (say that
I'd wish (a) to be tall enough to contain a 512x512 image plus the tabs,
(b) to be only 3-4 text lines, and (c) to occupy the rest of the page,
a bit less than the height of (a).
I tried with GridBagLayout, but that has SIDE EFFECTS ... as the various
components dynamically resize. Sometimes the myDisplay in (a) resizes
and loses the scrollbars, and this pushes the bottom of the Jtable in
(c) offscreen. While the message area in (b) grows higher than wished
and then remains like that.
This is the latest set of GridBagConstrains I tried (c1 c2 c3 for the
components (a) (b) (c) from top to bottom), but I tried several
variations.
c1.gridx=0 ; c1.gridy=0 ;
c1.gridwidth=GridBagConstraints.REMAINDER ;
c1.gridheight=10 ;
c1.fill=GridBagConstraints.BOTH ;
c1.anchor=GridBagConstraints.PAGE_START;
c1.weightx=1.0 ; c1.weighty=0.0 ;
c2.gridx=0 ; c1.gridy=11 ;
c2.gridwidth=GridBagConstraints.REMAINDER ;
c2.gridheight=5 ;
c2.fill=GridBagConstraints.BOTH ;
c2.anchor=GridBagConstraints.LINE_END ;
c2.weightx=1.0 ; c2.weighty=0.0 ;
c3.gridx=0 ; c1.gridy=16 ;
c3.gridwidth=GridBagConstraints.REMAINDER ;
c3.gridheight=GridBagConstraints.REMAINDER ;
c3.fill=GridBagConstraints.BOTH ;
c3.anchor=GridBagConstraints.PAGE_END;
c3.weightx=1.0 ; c3.weighty=0.0 ;
How can I achieve what I want i.e. three vertical sections of FIXED
DIFFERENT heights, which never resize, but in which scroll bars appear
when needed ?

Signature
----------------------------------------------------------------------
nospam@mi.iasf.cnr.it is a newsreading account used by more persons to
avoid unwanted spam. Any mail returning to this address will be rejected.
Users can disclose their e-mail address in the article if they wish so.
Knute Johnson - 18 Feb 2008 19:31 GMT
> I have nearly finished my Applet and I'm now left only to finalize the
> layout. So far I've used a GridLayout(3, 1) but now want to change to
[quoted text clipped - 77 lines]
> DIFFERENT heights, which never resize, but in which scroll bars appear
> when needed ?
Use GridBagLayout and set the gridx constraint to 0 for all three
components. Set the preferred sizes of the containers to what you want
them to be.

Signature
Knute Johnson
email s/nospam/knute/
LC's No-Spam Newsreading account - 19 Feb 2008 10:50 GMT
>> How can I achieve what I want i.e. three vertical sections of FIXED
>> DIFFERENT heights, which never resize, but in which scroll bars appear
>> when needed ?
>
> Use GridBagLayout and set the gridx constraint to 0 for all three components.
gridx was already set to zero as it was visible from the code I
included. I'm confused about whether the rest of the code is of any real
use.
> Set the preferred sizes of the containers to what you want them to be.
Thanks, that did the trick.
It's the containers that matter !

Signature
----------------------------------------------------------------------
nospam@mi.iasf.cnr.it is a newsreading account used by more persons to
avoid unwanted spam. Any mail returning to this address will be rejected.
Users can disclose their e-mail address in the article if they wish so.
Knute Johnson - 19 Feb 2008 18:23 GMT
>>> How can I achieve what I want i.e. three vertical sections of FIXED
>>> DIFFERENT heights, which never resize, but in which scroll bars appear
[quoted text clipped - 6 lines]
> included. I'm confused about whether the rest of the code is of any real
> use.
What I should have said was only set gridx to 0 and forget all the rest.
>> Set the preferred sizes of the containers to what you want them to be.
>
> Thanks, that did the trick.
> It's the containers that matter !
Excellent!

Signature
Knute Johnson
email s/nospam/knute/
------->>>>>>http://www.NewsDem
Roedy Green - 19 Feb 2008 23:36 GMT
On Mon, 18 Feb 2008 16:43:18 +0100, LC's No-Spam Newsreading account
<nospam@mi.iasf.cnr.it> wrote, quoted or indirectly quoted someone who
said :
>I played around with a GridBagLayout() but I'm getting
>unexpected resizing effects.
see http://mindprod.com/jgloss/gridbaglayout.html for some tips on
making it behave.
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Roedy Green - 21 Feb 2008 16:00 GMT
On Tue, 19 Feb 2008 23:36:18 GMT, Roedy Green
<see_website@mindprod.com.invalid> wrote, quoted or indirectly quoted
someone who said :
>>I played around with a GridBagLayout() but I'm getting
>>unexpected resizing effects.
>
>see http://mindprod.com/jgloss/gridbaglayout.html for some tips on
>making it behave.
>--
You might find it easier to split your layout into JPanels and do each
separately, then use a layout to arrange the JPanels. GridbagLayout
is "squirmier". You change anything and it can change everything.
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com