Java Reference
In-Depth Information
KeyEvent method getKeyModifiersText (p. 528) returns a string containing the pressed modifi-
er keys.
Section 12.18 Introduction to Layout Managers
• Layout managers (p. 528) arrange GUI components in a container for presentation purposes.
• All layout managers implement the interface LayoutManager (p. 528) of package java.awt .
Container method setLayout specifies the layout of a container.
FlowLayout places components left to right in the order in which they're added to the container.
When the container's edge is reached, components continue to display on the next line. FlowLayout
allows GUI components to be left aligned, centered (the default) and right aligned.
FlowLayout method setAlignment (p. 532) changes the alignment for a FlowLayout .
BorderLayout (p. 532) the default for a JFrame ) arranges components into five regions: NORTH ,
SOUTH , EAST , WEST and CENTER . NORTH corresponds to the top of the container.
•A BorderLayout limits a Container to containing at most five components—one in each region.
GridLayout (p. 536) divides a container into a grid of rows and columns.
Container method validate (p. 537) recomputes a container's layout based on the current lay-
out manager for the Container and the current set of displayed GUI components.
Section 12.19 Using Panels to Manage More Complex Layouts
• Complex GUIs often consist of multiple panels with different layouts. Every JPanel may have
components, including other panels, attached to it with Container method add .
Section 12.20 JTextArea
•A JTextArea (p. 539)—a subclass of JTextComponent —may contain multiple lines of text.
• Class Box (p. 540) is a subclass of Container that uses a BoxLayout layout manager (p. 541) to
arrange the GUI components either horizontally or vertically.
Box static method createHorizontalBox (p. 541) creates a Box that arranges components from
left to right in the order that they're attached.
•Method getSelectedText (p. 541) returns the selected text from a JTextArea .
• You can set the horizontal and vertical scrollbar policies (p. 542) of a JScrollPane when it's con-
structed. JScrollPane methods setHorizontalScrollBarPolicy (p. 542) and setVertical-
ScrollBarPolicy (p. 542) can be used to change the scrollbar policies at any time.
Self-Review Exercises
12.1
Fill in the blanks in each of the following statements:
a)
Method is called when the mouse is moved with no buttons pressed and an
event listener is registered to handle the event.
b)
Text that cannot be modified by the user is called
text.
c)
A(n)
arranges GUI components in a Container .
d)
The add method for attaching GUI components is a method of class
.
e)
GUI is an acronym for
.
f)
Method
is used to specify the layout manager for a container.
g)
A mouseDragged method call is preceded by a(n)
method call and followed by
a(n)
method call.
h)
Class
contains methods that display message dialogs and input dialogs.
i)
An input dialog capable of receiving input from the user is displayed with method
of class
.
Search WWH ::




Custom Search