JFrame setSize...

Hi there,

I have been fiddling with exclusive fullscreen and now all of a sudden setSize on a JFrame also takes decorations into account. What I am trying to say is that I believe that setSize is supposed to set the size of the content of the JFrame, and not the complete window.

Lets say I do a this.setSize(320,240); on a JFrame extended object, then the physical representation of the window ( the content, menubar etc.) is 320x240. I recall setSize setting size of the content in window.

Any hints on this one?

Try setting the size of the content pane.

That does not affect the frame at all. Strange though, since a this.getContentPane( ) should return the JFrame that I am using.

pack() your JFrame to let it adjust its size to its contents.

As far as I can say, setsize always worked on the outer bounds of a frame, with or without decoration.
Either you count the deco in or use setDecorated(false).

-JAW

[quote]pack() your JFrame to let it adjust its size to its contents.
[/quote]
Actually, I tried that. adding a JPanel that is set to a size to the JFrame and then pack( ); that JFrame. The JFrame is then something like (0,10) in size.

I will have a look at it again… I mean, that IS the way to do it. unless there is some undocumented… do a setVisible first after a pack( ), but only in case you have a undecorated JFrame… or something obscure like that.

Don’t do setSize but do setPreferredSize

[quote]Don’t do setSize but do setPreferredSize
[/quote]
Thanks, that hit the spot. :slight_smile: