|Co-ordinate System||JFrame Closing|
|JFrame State||Learning More|
|IsA vs HasA||Links|
When you specify the Jframe size, make it 22 pixels wider and 32 pixels taller than you need for the contents to allow room for the top Jframe bar. To add to the confusion, the origin is in the top corner under the Jframe bar. So you must add 32 to all your y coordinates inside a Jframe. This is one more reason to use layouts and avoid absolute positioning.
There are four way Jframe sizes could have been measured: all combinations of including or excluding the title bar and including or excluding the border. Oracle chose to include both. The easiest way to calculate a Jframe size is to manually adjust the Jframe until it looks right, then take a snapshot of it with PaintShop Pro, including the title bar and borders and use PSP’s size as your jFrame.setSize to set the initial size.
// turn off the entire frame bar, including title, close, minimize, resize... frame.setUndecorated( true ); // turn off just resizing controls frame.setResizable( false );
// You can control the current state of the Frame, // but you cannot disable the corresponding user controls. // To control the widgets, use a JInternalFrame. frame.setExtendedState( NORMAL ); frame.setExtendedState( ICONIFIED ); frame.setExtendedState( MAXIMIZED_HORIZ ); frame.setExtendedState( MAXIMIZED_VERT ); frame.setExtendedState( MAXIMIZED_BOTH );
Beware. getExtendedState in a componentResized event handler gives you the old state. You could use SwingUtilities. invokeLater or EventQueue. invokeLater to probe the new state.
There are two techniques for creating a frame full of components.
Here is a typical debugging harness you would append to every Jframe you write. Note how all initialisation is done on the Swing event thread via SwingUtilities.
Normally the caller who instantiates the Jframe does a setSize to determine its size, then a setLocation to position it, then a validate and finally a setVisible ( true ).
You might do a setSize and setLocation in the constructor, but definitely not a setVisible. setTitle may be done by either.
This page is posted
Optional Replicator mirror
Your face IP:[188.8.131.52]
You are visitor number|