I'm using JGoodies Forms and Looks and I'm generally am very happy with
it. I have one nagging problem, however, that crops up in a lot of
places in my app.
Basically, the problem is in the use of a subsidiary JPanel used within
a main JPanel. I use FormLayout and PanelBuilder to create both
JPanels. In the following example, the subsidiary panel is called,
MyTablePanel, that uses the following layout code to layout a JTable on
the left and a button stack on the right.
FormLayout layout = new FormLayout(
"fill:max(p;100dlu):grow, 7dlu, p",
"fill:max(p;40dlu):grow");
PanelBuilder builder = new PanelBuilder(this, layout);
builder.setBorder(Borders.EMPTY_BORDER);
// Fill the panel with labels and components.
CellConstraints cc = new CellConstraints();
// Create/add a JTable on the left side of the panel
JTable myJTable = new JTable();
JScrollPane scroller = new JScrollPane(myJTable);
builder.add(scroller, cc.xy(1, 1));
// Create/add a button stack to the right side of the panel
ButtonStackBuilder bb = new ButtonStackBuilder();
bb.addGridded(addButton);
bb.addRelatedGap();
bb.addGridded(editButton);
bb.addUnrelatedGap();
bb.addGridded(removeButton);
builder.add(bb.getPanel(), cc.xy(3, 1));
I then create a main JPanel that incorporates a few components
including the subsidiary JPanel, MyTablePanel. I use the following code
to layout the main JPanel to place MyTablePanel on top, a JLabel and
JTextArea below, followed by another JLabel and JTextArea below that:
FormLayout layout = new FormLayout(
"fill:p:grow",
"fill:max(p;50dlu):grow, 3dlu, p, 3dlu,
fill:max(p;50dlu):grow, 3dlu, p, 3dlu, fill:max(p;50dlu):grow");
PanelBuilder builder = new PanelBuilder(this, layout);
builder.setBorder(Borders.EMPTY_BORDER);
CellConstraints cc = new CellConstraints();
// Add the subsidiary JPanel
MyTablePanel myTablePanel = new MyTablePanel();
add(myTablePanel, cc.xy(1, 1));
// Add a label and JTextArea
add(new JLabel("Natural Language"), cc.xy(1, 3));
JTextArea natLangFld = new JTextArea();
JScrollPane natLangScroller = new JScrollPane(natLangFld);
add(natLangScroller, cc.xy(1, 5));
// Add another label and JTextArea
add(new JLabel("Programming Code"), cc.xy(1, 7));
JTextArea codeFld = new JTextArea();
JScrollPane codeScroller = new JScrollPane(codeFld);
add(codeScroller, cc.xy(1, 9));
If I run the subsidiary JPanel standalone in a JFrame, it I can resize
width-wise with no problem. I can expand the window using mouse-drag on
the JFrame edge and contract it -- the JTable expands and contracts,
leaving room to display the JButton stack.
**** PROBLEM *****
If I run the main JPanel standalone in a JFrame, it displays correctly
upon startup, and expands correctly. The subsidiary JPanel and the two
JTextArea instances in the main JPanel expand as I expand the window,
leaving room for the subsidiary JPanel's button stack. However, if I
then reduce the window's width (again, by mouse-dragging on the JFrame
edge), the 2 JTextAreaS contract width-wise, but the JTable (inside the
subsidiary JPanel) does not contract, leaving it cut-off by the right
side of the JFrame window. The button stack in the subsidiary JPanel is
cut-off from view, as well, of course.
I don't want to combine this into one big JPanel with a single
FormLayout because I reuse the subsidiary JPanel in several other
higher level JPanels. In addition, this is but one of many instances of
using this type of hierarchical gui structure in my application, so
doing so would seriously degrade my application architecture and
supportability.
If anyone can help me solve this problem, I would be very much
indebted.
Thank you,
Rick
Karsten Lentzsch - 03 Jan 2005 20:06 GMT
> **** PROBLEM *****
>
> [...] However, if I
> then reduce the window's width (again, by mouse-dragging on the JFrame
> edge), the 2 JTextAreaS contract width-wise, but the JTable (inside the
> subsidiary JPanel) does not contract, [...]
See the Forms FAQ 3.6 that ships with the Forms 1.0.5.
Also see the new pitfalls section in the Forms tutorial.
Likely its the JTextArea and its (re)-sizing behavior
that nags you. If you can't get it to work without
further help, please post a stripped example with
just the JTextArea and simpler 'rests' to the Forms
user mailing list: users at forms.dev.java.net
Hope this helps. Best regards,
Karsten Lentzsch
Andrew Thompson - 04 Jan 2005 11:42 GMT
> If you can't get it to work without
> further help, please post a stripped example with
> just the JTextArea and simpler 'rests' to the Forms
> user mailing list: users at forms.dev.java.net
Sounds just like an SSCCE.
<http://www.physci.org/codes/sscce.jsp>

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
rick333 - 05 Jan 2005 00:49 GMT
Thanks...it was a JTextArea resize problem. I wasn't aware of the
forms.dev.java.net site. I read 3.6 of the FAQ and solved my problem. I
really appreciate your help and your forms and looks libraries.