26.07.2013 Views

Java How to Program Fourth Edition - DCC

Java How to Program Fourth Edition - DCC

Java How to Program Fourth Edition - DCC

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

796 Graphical User Interface Components: Part 2 Chapter 13<br />

• The horizontal and vertical scrollbar policies for a JScrollPane are set when a JScroll-<br />

Pane is constructed or with methods setHorizontalScrollBarPolicy and setVerticalScrollBarPolicy<br />

of class JScrollPane.<br />

• A JPanel can be used as a dedicated drawing area that can receive mouse events and is often<br />

extended <strong>to</strong> create new GUI components.<br />

• Swing components that inherit from class JComponent contain method paintComponent,<br />

which helps them draw properly in the context of a Swing GUI. JComponent method paint-<br />

Component should be overridden <strong>to</strong> call <strong>to</strong> the superclass version of paintComponent as the<br />

first statement in its body.<br />

• Classes JFrame and JApplet are not subclasses of JComponent; therefore, they do not contain<br />

method paintComponent (they have method paint).<br />

• Calling repaint for a Swing GUI component indicates that the component should be painted as<br />

soon as possible. The background of the GUI component is cleared only if the component is<br />

opaque. Most Swing components are transparent by default. JComponent method setOpaque<br />

can be passed a boolean argument indicating whether the component is opaque (true) or transparent<br />

(false). The GUI components of package java.awt are different from Swing components<br />

in that repaint results in a call <strong>to</strong> Component method update (which clears the<br />

component’s background) and update calls method paint (rather than paintComponent).<br />

• Method setTitle displays a String in a window’s title bar.<br />

• Drawing on any GUI component is performed with coordinates that are measured from the upperleft<br />

corner (0, 0) of that GUI component.<br />

• Layout managers often use a GUI component’s getPreferredSize method <strong>to</strong> determine the<br />

preferred width and height of a component when laying out that component as part of a GUI. If a<br />

new component has a preferred width and height, it should override method getPreferred-<br />

Size <strong>to</strong> return that width and height as an object of class Dimension (package java.awt).<br />

• The default size of a JPanel object is 0 pixels wide and 0 pixels tall.<br />

• A mouse drag operation begins with a mouse-pressed event. All subsequent mouse drag events<br />

(for which mouseDragged will be called) are sent <strong>to</strong> the GUI component that received the original<br />

mouse-pressed event.<br />

• JSliders enable the user <strong>to</strong> select from a range of integer values. JSliders can display major<br />

tick marks, minor tick marks and labels for the tick marks. They also support snap-<strong>to</strong> ticks, where<br />

positioning the thumb between two tick marks causes the thumb <strong>to</strong> snap <strong>to</strong> the closest tick mark.<br />

• Most Swing GUI components support user interactions through both the mouse and the keyboard.<br />

• If a JSlider has the focus, the left arrow key and right arrow key cause the thumb of the<br />

JSlider <strong>to</strong> decrease or increase by 1. The down arrow key and up arrow key also cause the<br />

thumb of the JSlider <strong>to</strong> decrease or increase by 1, respectively. The PgDn key (page down) and<br />

PgUp key (page up) cause the thumb of the JSlider <strong>to</strong> decrease or increase by block increments<br />

of one-tenth of the range of values, respectively. The Home key moves the thumb <strong>to</strong> the minimum<br />

value of the JSlider and the End key moves the thumb <strong>to</strong> the maximum value of the JSlider.<br />

• JSliders have either a horizontal orientation or a vertical orientation. For a horizontal JSlider,<br />

the minimum value is at the extreme left and the maximum value is at the extreme right of the<br />

JSlider. For a vertical JSlider, the minimum value is at the extreme bot<strong>to</strong>m and the maximum<br />

value is at the extreme <strong>to</strong>p of the JSlider. The relative position of the thumb indicates the<br />

current value of the JSlider.<br />

• Method setMajorTickSpacing of class JSlider sets the spacing for tick marks on a JSlider.<br />

Method setPaintTicks with a true argument indicates that the tick marks should<br />

be displayed.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!