A scrollbar (Jscrollbar), also known as a slider, is used to represent a relative value that represents an integer in the specified range. For example, when you edit a document in Word, the slider to the right of the edit window corresponds to the position of the current edit position in the entire document, and you can move to select a new edit location. In swing, the Jscrollbar class is used to implement and manage the adjustable interface. The common construction methods of the Jscrollbar class are:
Jscrollbar (int dir,int init,int width,int low,int High)
Where dir indicates the direction of the scroll bar. The Jscrollbar class defines two constants, jscrollbar.vertical represents a vertical scrollbar, and jscrollbar.horizontal represents a horizontal scroll bar. Init represents the initial value of the ScrollBar, which determines the position at which the ScrollBar slider starts, the width of the scrollbar slider, and the last two parameters that specify the lower and upper bounds of the scroll bar. Note the width of the slider may affect the actual maximum value that can be obtained by the scroll bar. For example, the scroll bar range is 0 to 255, the width of the slider is 10, and the left or top edge of the slider is used to determine its actual position. The maximum value that the scroll bar can reach is the specified maximum value minus the width of the slider. Therefore, the value of the scroll bar will not exceed 245.
Other common methods of the Jscrollbar class are:
- Setunitincrement (): Sets the increment, that is, the increment of unit pixels;
- Getunitincrement (): Gets the increment;
- Setblockincrement (): Sets the increment of the slider, that is, the amplitude of the slider;
- Getblockincrement (): Gets the slider increment;
- Setmaxinum (): Sets the maximum value;
- Getmaxinum (): Gets the maximum value;
- Setmininum (): Sets the minimum value;
- Getmininum (): Gets the minimum value;
- SetValue (): Sets the new value;
- GetValue (): Gets the current value.
The event type of the Jscrollbar class object is adjustmentevent; The interface to be implemented by the class is Adjustmentlistener, and the interface method is adjustmentvaluechanged (); The method to register the monitor is Addadjustmentlistener (); The method to get the event source object is Getadjustable ().
The method defined by the Myscrollbar class Getpreferedsize () is also a method defined in the component class, and the interface component determines the size of the interface component by overriding the method that defines it. When the layout word processor arranges the component layout, it calls the method to determine the size of the component. This method returns an object of type dimension, with a dimension object containing two integers, the width and height of the component.
Series Articles:
Java know how much (top)Java know how much (medium)Java knows how many () Java vectors (vector) and their applicationsJava know how much (79) hash table and its applicationJava know how much (80) graphical Interface design basicsJava know how much (81) frame window BasicsJava know how much (82) Introduction to tags, buttons, and button eventsJava know how much (83) Panel Basics: JPanel and JScrollPaneJava know how much (84) layout design of graphical interfaceJava know how much (85) text box and text areaJava know how much (86) input and output of text box and text areaJava know how much (87) Select boxes and radio buttonsJava know how many (88) lists and combo boxesJava know how many (89) lists and combo boxesJava know how much (90) menuJava know how much (91) dialog box
Java know how much (92) scroll bar