
Signature
Eric Sosman
esosman@acm-dot-org.invalid
> > Hi,
>
[quoted text clipped - 17 lines]
> Eric Sosman
> esos...@acm-dot-org.invalid
i am not very sure whether the box layout fulfills my second and third
requirements
Eric Sosman - 17 Feb 2007 14:24 GMT
>>> Hi,
>>> Can anyone suggest a layout manager which would do the following:
[quoted text clipped - 6 lines]
> i am not very sure whether the box layout fulfills my second and third
> requirements
It does -- or so it seems to me; I may have misunderstood
your requirements. Why not try it for yourself?

Signature
Eric Sosman
esosman@acm-dot-org.invalid
On Ali - 17 Feb 2007 14:33 GMT
> >>> Hi,
> >>> Can anyone suggest a layout manager which would do the following:
[quoted text clipped - 13 lines]
> Eric Sosman
> esos...@acm-dot-org.invalid
i have actually seen the screenshots on the sun site.... i takes the
preferred width of the component and not the total available width of
the container
a249@mailinator.com - 17 Feb 2007 16:17 GMT
> i am not very sure whether the box layout fulfills my second and third
> requirements
Why don't you try it?
Larry Barowski - 17 Feb 2007 17:30 GMT
> i am not very sure whether the box layout fulfills my second and third
> requirements
It depends on what you mean by the second one. For
a vertical orientation I believe it will make all the
components the same width, if they aren't restricted by
maximum width. If it's a column of buttons for example,
they will all be as wide as the largest preferred width.
If the panel is on one side of a split pane or something
and you want the components to fill the width of the
panel but for the panel still to have a meaningful
preferred width, then GridBagLayout would be easy
enough, or you could write your own layout to do this
in about ten minutes. For the simplest case (minimum
size == preferred size, tightly packed components,
align to top, no respect for maximum sizes) you could
do something like (untested, may contain errors):
public Dimension preferredLayoutSize(Container parent) {
Component[] children = parent.getComponents();
Dimension psize = new Dimension();
for(int c = 0; c < children.length; c++) {
Dimension child_psize = children[c].getPreferredSize();
psize.height += child_psize.height;
psize.width = Math.max(psize.width, child_psize.width); }
Insets insets = parent.getInsets();
psize.width += insets.left + insets.right;
psize.height += insets.top + insets.bottom;
return psize;
}
public Dimension minimumLayoutSize(Container parent) {
return preferredLayoutSize(parent);
}
public void layoutContainer(Container parent) {
Dimension msize = minimumLayoutSize(parent);
Insets insets = parent.getInsets();
int w = Math.max(parent.getSize().width, msize.width) -
insets.left - insets.right;
int x = insets.left;
int y = insets.top;
Component[] children = parent.getComponents();
for(int c = 0; c < children.length; c++) {
Component child = children[c];
Dimension child_psize = child.getPreferredSize();
child.setLocation(x, y);
child.setSize(w, child_psize.height);
y += child_psize.height;
}
}
public void addLayoutComponent(String name,
Component comp) {
}
public void removeLayoutComponent(Component comp) {
}