Java Reference
In-Depth Information
fBlue.addChangeListener (this);
} // ctor
/** This class is the AdjustmentListener for the
* slider. So the events come here when the
* slider is moved.
**/
public void stateChanged (ChangeEvent evt) {
// Use the labels to show the numerical values of the
// scroll bar settings.
fRedLabel.setText ("Red " + fRed.getValue ());
fGreenLabel.setText ("Green " + fGreen.getValue ());
fBlueLabel.setText ("Blue " + fBlue.getValue ());
// Get the values from each scroll bar and pass
// them as the color component values.
fOutputPanel.setColor (fRed.getValue (),
fGreen.getValue (),
fBlue.getValue ());
fOutputPanel.repaint ();
} // stateChanged
} // class SliderPanel
7.4 Layout managers
Yo u are now familiar with several Swing components and the basics of event
handling. You can build quite elaborate interfaces. However, before proceeding
you need to know how to control the arrangement, or layout ,ofthe components.
With Java you do not normally give components fixed numerical dimensions
and coordinate locations. Java is intended to be portable to different platforms with
different graphical operating systems and with different types of display devices.
Aflexible approach to component arrangement is thus required. This flexibility
is achieved with layout managers ,which we briefly mentioned in Chapter 6. A
layout manager follows a general set of design rules as to how it should arrange
components. You give it instructions and the layout manager tries its best to follow
them within its own framework for how components are arranged.
Note that the layout manager can try to expand or shrink the size of a compo-
nent to fit the layout. However, it cannot arbitrarily modify the size of a component
 
Search WWH ::




Custom Search