Tips | Caller/Callee Responsibility |
Co-ordinate System | JFrame Closing |
JFrame State | Learning More |
IsA vs HasA | Links |
Debugging Harness |
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 |
http://mindprod.com/jgloss/jframe.html | |
Optional Replicator mirror
|
J:\mindprod\jgloss\jframe.html | |
Please read the feedback from other visitors,
or send your own feedback about the site. Contact Roedy. Please feel free to link to this page without explicit permission. | ||
Canadian
Mind
Products
IP:[65.110.21.43] Your face IP:[3.145.172.41] |
| |
Feedback |
You are visitor number | |