Java Reference
In-Depth Information
Maximized
internal frame
Fig. 22.12
|
Test class for
DeskTopFrame
. (Part 2 of 2.)
Lines 39-58 register an
ActionListener
to handle the event when the user selects the
newFrame
menu item. When the event occurs, method
actionPerformed
(lines 43-56)
creates a
JInternalFrame
object in lines 47-48. The
JInternalFrame
constructor used
here takes five arguments—a
String
for the title bar of the internal window, a
boolean
indicating whether the internal frame can be resized by the user, a
boolean
indicating
whether the internal frame can be closed by the user, a
boolean
indicating whether the
internal frame can be maximized by the user and a
boolean
indicating whether the internal
frame can be minimized by the user. For each of the
boolean
arguments, a
true
value indi-
cates that the operation should be allowed (as is the case here).
As with
JFrame
s and
JApplet
s, a
JInternalFrame
has a content pane to which GUI
components can be attached. Line 50 creates an instance of our class
MyJPanel
(declared
at lines 63-91) that is added to the
JInternalFrame
at line 51.
Line 52 uses
JInternalFrame
method
pack
to set the size of the child window.
Method
pack
uses the preferred sizes of the components to determine the window's size.
Class
MyJPanel
declares method
getPreferredSize
(lines 87-91) to specify the panel's
preferred size for use by the
pack
method. Line 54 adds the
JInternalFrame
to the
JDesk-
topPane
, and line 55 displays the
JInternalFrame
.
Classes
JInternalFrame
and
JDesktopPane
provide many methods for managing
child windows. See the
JInternalFrame
and
JDesktopPane
online API documentation
for complete lists of these methods:
docs.oracle.com/javase/7/docs/api/javax/swing/JInternalFrame.html
docs.oracle.com/javase/7/docs/api/javax/swing/JDesktopPane.html
A
JTabbedPane
arranges GUI components into layers, of which only one is visible at a
time. Users access each layer via a tab—similar to folders in a file cabinet. When the user
clicks a tab, the appropriate layer is displayed. The tabs appear at the top by default but
also can be positioned at the left, right or bottom of the
JTabbedPane
. Any component