Home

JFrame

In Java Swing, JFrame is a top-level window that provides a window with a title bar, borders, and standard window controls. It is part of the javax.swing package and serves as a primary top-level container for building graphical user interfaces.

JFrame extends java.awt.Frame and contains a JRootPane which holds a layered pane, a content pane for application

Common operations include setTitle, pack, setSize, setResizable, setLocationRelativeTo, and setVisible. The frame also supports setDefaultCloseOperation with

Lifecycle: after construction, the frame is configured, then made visible by setVisible(true). Closing the frame disposes

See also: Event Dispatch Thread, Swing, RootPaneContainer.

components,
and
an
optional
glass
pane.
Components
are
added
to
the
frame’s
content
pane
via
getContentPane()
or
by
calling
add,
which
delegates
to
the
content
pane.
The
content
pane
is
typically
a
JPanel
with
a
layout
manager.
options
DO_NOTHING_ON_CLOSE,
HIDE_ON_CLOSE,
DISPOSE_ON_CLOSE,
and
EXIT_ON_CLOSE
to
control
behavior
when
the
user
closes
the
window.
Frames
can
also
host
a
menu
bar
through
setJMenuBar
and
can
customize
the
icon
via
setIconImage.
of
native
resources,
and
if
EXIT_ON_CLOSE
is
set,
terminates
the
application.
Best
practice
is
to
construct
and
manipulate
Swing
components
on
the
Event
Dispatch
Thread
to
ensure
thread
safety
and
proper
UI
behavior.