Package java.awt Previous
Previous
Java API
Java API
Index
Index
Next
Next

Class Scrollbar

Fields , Constructors , Methods

public  class  java.awt.Scrollbar
    extends  java.awt.Component  
{
        // Fields
    public final static int HORIZONTAL;	
    public final static int VERTICAL;	

        // Constructors
    public Scrollbar();	
    public Scrollbar(int  orientation);	
    public Scrollbar(int  orientation, int  value,	
                 int  visible, int  minimum, int  maximum);

        // Methods
    public void addNotify();	
    public int getLineIncrement();	
    public int getMaximum();	
    public int getMinimum();	
    public int getOrientation();	
    public int getPageIncrement();	
    public int getValue();	
    public int getVisible();	
    protected String paramString();	
    public void setLineIncrement(int  l);	
    public void setPageIncrement(int  l);	
    public void setValue(int  value);	
    public void setValues(int  value, int  visible,	
                            int  minimum, int  maximum);
}

A scroll bar provides a convenient means of allowing a user to select from a range of values. For example, the following three scrollbars could be used to pick the each of the red, green, and blue components of a color:

Each scrollbar was created with the code like the following:

redSlider=new Scrollbar(Scrollbar.VERTICAL, 0, 1, 0, 255);
add(redSlider); 

Alternatively, a scroll bar can represent a range of values. For example, if using a scrollbar for scrolling through text, the width of the "bubble" can represent the amount of text visible. Here is an example of a scrollbar representing a range:

The value range represented by the bubble is the visible amount of the scrollbar.

The code to produce the above scrollbar is

ranger = new Scrollbar(Scrollbar.HORIZONTAL, 0, 64, 0, 255);
add(ranger); 

Note that the maximum value above, 255, is the maximum value for the "left side" of the scroll bar.

In addition, whenever the user changes the value of the scroll bar, AWT sends one of the following five events to the user:

The event's target is the scroll bar, and its object is an Integer giving the value represented by the scroll bar

If an application wants to perform some action when the value in a scroll bar is changed, it must override handleEvent method of the scroll bar or of one of its containing windows. The code to perform that should be of the following form:


public boolean handleEvent(Event event) {
        if (event.target == scrollbar) { 
                do something
                return true;
        } else {
                return super.handleEvent(event);
        }
}    



Fields


HORIZONTAL

public final static int HORIZONTAL = 0 

Constant indicating to construct a horizontal scroll bar.


VERTICAL

public final static int VERTICAL = 1 

Constant indicating to construct a vertical scroll bar.


Constructors


Scrollbar

public Scrollbar() 

Constructs a new vertical scroll bar.


Scrollbar

public Scrollbar(int  orientation) 

Constructs a new scroll bar with the specified orientation.

The orientation argument must be one of the two values Scrollbar.HORIZONTAL Scrollbar.VERTICAL indicating a horizontal or vertical scroll bar, respectively.

ParameterDescription
orientation indicates the orientation of the scroll bar.

Throw:

IllegalArgumentException

When an illegal orientation is given.


Scrollbar

public Scrollbar(int  orientation, int  value, int  visible,
                                  int  minimum, int  maximum) 

Constructs a new scroll bar with the specified orientation, initial value, page size, and minumum and maximum values.

The orientation argument must be one of the two values Scrollbar.HORIZONTAL Scrollbar.VERTICAL indicating a horizontal or vertical scroll bar, respectively.

If the specified maximum value is less than the minimum value, it is changed to be the same as the minimum value. If the initial value is lower than the minimum value, it is changed to be the minimum value; if it is greater than the maximum value, it is changed to be the maximum value.

ParameterDescription
orientation indicates the orientation of the scroll bar.
value the initial value of the scroll bar
visible the size represented by the bubble in the scroll bar. The sroll bar uses this value when paging up or down by a page.
minimum the minimum value of the scrollbar
maximum the maximum value of the scrollbar


Methods


addNotify

public void addNotify() 

This method calls the createScrollbar method of this object's toolkit in order to create a ScrollbarPeer for this button. This peer allows the application to change the look of a scroll bar without changing its functionality.

Most applications do not call this method directly.

Overrides:

addNotify in class Component .


getLineIncrement

public int getLineIncrement() 

Determines the line increment of this scrollbar, which is the amount that is added or subtracted from this scroll bar's value when the user hits the down or up gadget.

Return Value:

Returns the line increment of this scroll bar.

See Also: setLineIncrement .


getMaximum

public int getMaximum() 

Return Value:

Returns the maximum value of this scroll bar.

See Also: getMinimum getValue .


getMinimum

public int getMinimum() 

Return Value:

Returns the maximum value of this scroll bar.

See Also: getMaximum getValue .


getOrientation

public int getOrientation() 

Determines the orientation of this scroll bar. The value returned is either HORIZONTAL or VERTICAL

Return Value:

Returns the orientation of this scroll bar.


getPageIncrement

public int getPageIncrement() 

Determines the page increment of this scroll bar, which is the amount that is added to or subtracted from this scroll bar' value when the user hits the page down or page up gadget.

Return Value:

Returns the page increment for this scroll bar.

See Also: getsetPageIncrement .


getValue

public int getValue() 

Return Value:

Returns the current value of this scroll bar.

See Also: getMinimum getMaximum .


getVisible

public int getVisible() 

Determines the "visible" amount of this scroll bar, which is the range of values represented by the width of the bubble in this scroll bar.

Return Value:

Returns the "visible" amount of this scroll bar.


paramString

protected String paramString() 

Returns the parameter string representing the state of this scroll bar. This string is useful for debugging.

Return Value:

Returns the parameter string of this scroll bar.

Overrides:

paramString in class Component .


setLineIncrement

public void setLineIncrement(int  l) 

Sets the line increment of this scroll bar.

The line increment is the value that is added to or subtracted from the value of this scroll bar when the user hits the line down or line up gadget.

ParameterDescription
l the new line increment

See Also: getLineIncrement .


setPageIncrement

public void setPageIncrement(int  l) 

Sets the page increment of this scroll bar.

The page increment is the value that is added to or subtracted from the value of the scroll bar when the user hits the page down or page up gadget.

ParameterDescription
l the new page increment

See Also: getPageIncrement .


setValue

public void setValue(int  value) 

Sets the value of this scroll bar to the specified value. If the specified value is below this scroll bar's current minimum or above the current maximum, it becomes the minimum or maximum value, respectively.

ParameterDescription
value the new value of this scroll bar

See Also: getValue .


setValues

public void setValues(int  value, int  visible,
                                            int  minimum, int  maximum) 

Sets several parameters of this scroll bar simultaneously..

ParameterDescription
value the value of this scroll bar
visible the amount visible per page
minimum the minimum value of this scroll bar
maximum the maximum value of this scroll bar



Top© 1996 Sun Microsystems, Inc. All rights reserved.