Java Reference
In-Depth Information
22.1 Introduction
22.2 JSlider
22.3 Understanding Windows in Java
22.4 Using Menus with Frames
22.5 JPopupMenu
22.6 Pluggable Look-and-Feel
22.7 JDesktopPane and JInternalFrame
22.8 JTabbedPane
22.9 BoxLayout Layout Manager
22.10 GridBagLayout Layout Manager
22.11 Wrap-Up
Summary | Self-Review Exercises | Answers to Self-Review Exercises | Exercises
22.1 Introduction
In this chapter, we continue our study of Swing GUIs. We discuss additional components
and layout managers and lay the groundwork for building more complex GUIs. We begin
with sliders for selecting from a range of integer values, then discuss additional details of
windows. Next, you'll use menus to organize an application's commands.
The look-and-feel of a Swing GUI can be uniform across all platforms on which a Java
program executes, or the GUI can be customized by using Swing's pluggable look-and-
feel ( PLAF ). We provide an example that illustrates how to change between Swing's
default metal look-and-feel (which looks and behaves the same across platforms), the
Nimbus look-and-feel (introduced in Chapter 12), a look-and-feel that simulates Motif (a
UNIX look-and-feel) and one that simulates the Microsoft Windows look-and-feel.
Many of today's applications use a multiple-document interface (MDI) a main
window (often called the parent window ) containing other windows (often called child
windows ) to manage several open documents in parallel. For example, many e-mail pro-
grams allow you to have several e-mail windows open at the same time so that you can
compose or read multiple e-mail messages. We demonstrate Swing's classes for creating
multiple-document interfaces. Finally, you'll learn about additional layout managers for
organizing graphical user interfaces. We use several more Swing GUI components in later
chapters as they're needed.
Swing is now considered a legacy technology. For GUIs, graphics and multimedia in
new Java apps, you should use the features presented in this topic's JavaFX chapters.
Java SE 8: Implementing Event Listeners with Lambdas
Throughout this chapter, we use anonymous inner classes and nested classes to implement
event handlers so that the examples can compile and execute with both Java SE 7 and Java
SE 8. In many of the examples, you could implement the functional event-listener inter-
faces with Java SE 8 lambdas (as demonstrated in Section 17.9).
22.2 JSlider
JSlider s enable a user to select from a range of integer values. Class JSlider inherits from
JComponent . Figure 22.1 shows a horizontal JSlider with tick marks and the thumb that
allows a user to select a value. JSlider s can be customized to display major tick marks ,
minor tick marks and labels for the tick marks. They also support snap-to ticks , which
cause the thumb , when positioned between two tick marks, to snap to the closest one.
 
 
 
Search WWH ::




Custom Search