Java Reference
In-Depth Information
javax.swing.JComponent
The get and set methods for these data fields are provided
in the class, but omitted in the UML diagram for brevity.
javax.swing.JScrollBar
-orientation: int
-maximum: int
Specifies horizontal or vertical style, default is horizontal.
Specifies the maximum value the scroll bar represents when the bubble
reaches the right end of the scroll bar for horizontal style or the
bottom of the scroll bar for vertical style.
Specifies the minimum value the scroll bar represents when the bubble
reaches the left end of the scroll bar for horizontal style or the top of
the scroll bar for vertical style.
Specifies the relative width of the scroll bar's bubble. The actual width
appearing on the screen is determined by the maximum value and the
value of visibleAmount .
Represents the current value of the scroll bar.
Specifies value added (subtracted) when the user activates the block-
increment (decrement) area of the scroll bar, as shown in Figure
17.10.
Specifies the value added (subtracted) when the user activates the unit-
increment (decrement) area of the scroll bar, as shown in Figure
17.10.
-minimum: int
-visibleAmount: int
-value: int
-blockIncrement: int
-unitIncrement: int
+JScrollBar()
+JScrollBar(orientation: int)
+JScrollBar(orientation: int, value:
int, extent: int, min: int, max: int)
Creates a default vertical scroll bar.
Creates a scroll bar with the specified orientation.
Creates a scroll bar with the specified orientation, value, extent,
minimum, and maximum.
+addAdjustmentListener(listener:
AdjustmentListener): void
Adds an AdjustmentListener to this object.
F IGURE 17.11 JScrollBar enables you to select from a range of values.
Message panel
Vertical scroll bar
Horizontal scroll bar
F IGURE 17.12
The scroll bars move the message on a panel horizontally and vertically.
2. Process the event.
Create listeners to implement the adjustmentValueChanged handler to move the
message according to the bar movement in the scroll bars.
L ISTING 17.6 ScrollBarDemo.java
1 import java.awt.*;
2 import java.awt.event.*;
3 import javax.swing.*;
4
5 public class ScrollBarDemo extends JFrame {
6
// Create horizontal and vertical scroll bars
7
private JScrollBar jscbHort =
horizontal scroll bar
 
Search WWH ::




Custom Search