Swing Jframe
Swing Jframe
Swing Jframe
Introduction
The class JFrame is an extended version of java.awt.Frame that adds support for the JFC/Swing
component architecture.
Class declaration
Following is the declaration for javax.swing.JFrame class:
Field
Following are the fields for java.awt.Component class:
static int EXIT_ON_CLOSE -- The exit application default window close operation.
protected JRootPane rootPane -- The JRootPane instance that manages the contentPane
and optional menuBar for this frame, as well as the glassPane.
Class constructors
1 JFrame
2 JFrameGraphicsConfigurationgc
3 JFrameStringtitle
4 JFrameStringtitle, GraphicsConfigurationgc
Creates a JFrame with the specified title and the specified GraphicsConfiguration of a
screen device.
Class methods
4 AccessibleContext getAccessibleContext
5 Container getContentPane
6 int getDefaultCloseOperation
Returns the operation that occurs when the user initiates a "close" on this frame.
7 Component getGlassPane
8 Graphics getGraphics
9 JMenuBar getJMenuBar
10 JLayeredPane getLayeredPane
11 JRootPane getRootPane
12 TransferHandler getTransferHandler
Returns true if newly created JFrames should have their Window decorations provided by
the current look and feel.
Returns whether calls to add and setLayout are forwarded to the contentPane.
15 protected String paramString
17 void removeComponentcomp
19 void setContentPaneContainercontentPane
20 void setDefaultCloseOperationintoperation
Sets the operation that will happen by default when the user initiates a "close" on this
frame.
Provides a hint as to whether or not newly created JFrames should have their Window
decorations suchasborders, widgetstoclosethewindow, title. . . provided by the current look and
feel.
22 void setGlassPaneComponentglassPane
23 void setIconImageImageimage
24 void setJMenuBarJMenuBarmenubar
25 void setLayeredPaneJLayeredPanelayeredPane
26 void setLayoutLayoutManagermanager
29 void setTransferHandlerTransferHandlernewHandler
Sets the transferHandler property, which is a mechanism to support transfer of data into
this component.
30 void updateGraphicsg
Methods inherited
This class inherits methods from the following classes:
java.awt.Frame
java.awt.Window
java.awt.Container
java.awt.Component
java.lang.Object
JFrame Example
Create the following java program using any editor of your choice in say D:/ > SWING > com >
tutorialspoint > gui >
SwingContainerDemo.java
package com.tutorialspoint.gui;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public SwingContainerDemo(){
prepareGUI();
}
mainFrame.add(headerLabel);
mainFrame.add(controlPanel);
mainFrame.add(statusLabel);
mainFrame.setVisible(true);
}
Compile the program using command prompt. Go to D:/ > SWING and type the following
command.
D:\SWING>javac com\tutorialspoint\gui\SwingContainerDemo.java
If no error comes that means compilation is successful. Run the program using following
command.
D:\SWING>java com.tutorialspoint.gui.SwingContainerDemo