JFrame is a class in Java that is used to create a top-level container that provides a window on the screen. It is a base window on which other components rely, such as menu bars, panels, labels, text fields, buttons, etc. . It is a part of the Swing library and is used to create a GUI.
JFrame is a type of container that inherits the java.awt.Frame class. Unlike Frame, JFrame has the option to hide or close the window with the help of the setDefaultCloseOperation(int) method. The JFrame class is slightly incompatible with Frame. Like all other JFC/Swing top-level containers, a JFrame contains a JRootPane as its only child. The content pane provided by the root pane should, as a rule, contain all the non-menu components displayed by the JFrame.
JFrame has many constructors that are used to create a new JFrame. Some of the constructors are:
JFrame()
: This helps in creating a frame that is invisible.JFrame(String Title)
: Helps in creating a frame with a title.JFrame(GraphicsConfiguration gc)
: Creates a frame with a blank title and the graphics configuration of the screen.
JFrame class has various methods which can be used to customize it. Some of the common methods of the JFrame class are setSize()
, setVisible()
, setDefaultCloseOperation()
, setLayout()
, etc. .