On Fri, Sep 19, 2003 at 02:10:20PM -0400, email@example.com wrote:
> Hi Jacek,
> >When adding components into a BoxLayout (a list of
> >JLabels in my example), is there any way to make them
> >fill the full width of the component (sort of like a
> >GridLayout does, but only horizintally, not
> >I tried setting the miniminSize on all the labels,
> >but it seems to be getting ignored and always gets
> >resized to just the smallest possible one.
> You actually would want to set the maximum size. It is the maximum size
> that is preventing the labels from being stretched. Here's a line of
> label.setMaximumSize(new Dimension(Integer.MAX_VALUE,
One thing to be careful about with code like this is that if you ever
change a property that effects the height, like the font or border,
you may end up with a max height that is less than the preferred
height, which may confuse some layout managers. If you never
dynamically change these sort of properties, than this code shouldn't
be a problem.
Your use of this web site or any of its content or software indicates your agreement to be bound by these Terms of Participation.
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.