By heritage JFrame class and its descendant classes (subclasses direct) can use the data and / or methods of the superclass Frame, Window, Container, and Component Object awt library.
JFrame class is slightly incompatible with the Frame class. Like every other top-level container of the Swing library, a JFrame contains a JRootPane as its only element. The contentPane provided by the RootPane should as a rule, contain all non-menu components displayed by the JFrame.
Frame Unlike a JFrame has some notion of how to respond when the user tries to close the window. The default behavior is to simply hide the JFrame when the user closes the window. To change the default behavior is to invoke the method setDefaultCloseOperation ().
I. - CLASS HIERARCHY |
II .- METHODS |
ATTRIBUTES | ||
static int | EXIT_ON_CLOSE | The default output to close a window. |
BUILDERS | ||
| JFrame () | Create a new frame that is initially visible |
| JFrame (String title) | Create a new frame with the title indicated as a parameter |
METHODS | ||
Return Type Method | | Description |
Container | getContentPane () | Returns the contentPane object. |
int | getDefaultCloseOperation () | Returns the operation that occurs when the user operation closing the window frame |
JMenuBar | getJMenuBar () | Returns the MenuBar established in the frame |
void | remove (Component comp) | Remove the specified component as a parameter of this container |
void | setContentPane (Container contentPane) | Sets the contentPane property |
| setDefaultCloseOperation (int operation) | Sets the operation will happen by default when the user closes the window |
void | setJMenuBar (JMenuBar menu) | Sets the menubar for the frame |
void | setLayout (LayoutManager layout) | By default, the distribution of this component panels should not be changed; instead, it should be changed the distribution of its contentPane which is usually a panel. |
III .- OTHER METHODS |
- To Put the name in the window JFrame:
this.setTitle ("title frame ");
- To maximize JFrame window
this.setExtendedState (this.MAXIMIZED_BOTH)
- To disable the close button from JFrame
this.setDefaultCloseOperation (0) ;
this.setDefaultCloseOperation (this.DO_NOTHING_ON_CLOSE)
- To make the frame visible
this.setVisible (true);
NOTE: All of these methods must be invoked in the constructor of the JFrame; ie
public
public
Main () {
panAcceso panAcces = new ();
admin = new Manager ();
ListaAlumnos listadoAlu = new ();
initComponents ();
date = new Date () ;
/ / Maximize the window
this.setExtendedState JFrame (this.MAXIMIZED_BOTH)
/ / Prevents the frame with cierrre Esquival exit button to this.setDefaultCloseOperation (0);
this.setDefaultCloseOperation (this.DO_NOTHING_ON_CLOSE)
this.setTitle (INTEGRAL SYSTEM OF LETTERS - NO ");
lblFecha.setText (" "+ fecha.iniciarComponentes () )
try {
UIManager.setLookAndFeel (UIManager.getSystemLookAndFeelClassName ());
} catch (Exception e) {
e.printStackTrace ();
}}
IV .- EXAMPLES |
- Design an application with two frames, a welcome and a farewell activated through buttons as shown below: