Re: setting size of elements



On Sat, 27 Aug 2005 08:46:59 -0400, Frances wrote:

> setSiz() is ignored...

In deference to preferredSize, mostly.

> JButton btn = new JButton("OK");
> public void init() {
> getContentPane().add(btn);
> btn.setSize(80,20);
> }
>
> applet

(J)Applet..

>..is width=200 height=100, and this is size button comes out..
> if I put btn.setSize(80,20); _before_ getContentPane().add(btn); line
> it's also ignored...

Yes. The default layout of Swing root containers is BorderLayout,
and the default constraint for adding to a BorderLayout is
BorderLayout.CENTER.

> ..pls, how do you control size of elements?

If you need to - it is usually a warning that something is wrong.

But..
1) By setting the preferredSize (and to be safe,
the minimum/maximum sizes.
2) Adding the component to a layout that respects
the component's preferred size.

Have you done the layout tutorial and Swing tutorials
mentioned in the GUI FAQ?

--
Andrew Thompson
physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
"You know you done me wrong baby, and you'll be sorry someday."
B.B.King 'The Thrill Is Gone'
.