Class ScrollBar in AWT in Java

0
45
Spread the love
  • 28
  • 34
  • 56
  • 35
  •  
  •  
  •  
  • 12
  •  
  •  
    165
    Shares

Class ScrollBar in AWT in Java

This Component represents a graphical scrollbar. setValue() sets the displayed value of the scrollbar. setValues() sets the displayed value, the page size, and the minimum and maximum values. The constants HORIZONTAL and VERTICAL are legal values for the scrollbar orientation.

While list boxes contain their own scroll bars, it is useful to have scrollbars for selecting other kinds of the variable input. The ScrollBar is used to select continuous values between the given minimum and maximum. One can slide over this range.

It can also be either vertical or horizontal oriented. We register an interest in Scrollbar events by calling ass AdjustmentListener and receive events in the adjustmentValueChanged() method. There are several possible events that result in this method being called.

The Scrollbar is a Component that provides the means to get and set values within a predetermined range. For example, a scrollbar could be used for volume control. Scrollbars are most frequently used to help users manipulate areas too large to be displayed on the screen (pre-version 1.1) or to set a value within an integer range.

The class structure for ScrollBar is given as

public class java.awt.Scrollbar extends java.awt.Component implements java.awt.Adjustable {
//Member elements
UNIT_INCREMENT;//the scrollbar has been clicked at the top or bottom to move one unit up or bottom. 
UNIT_DECREMENT;//the scrollbar has been clicked just above or below the elevator causing a page up or page down event
BLOCK_INCREMENT; //The elevator has been dragged to a new position.
BLOCK_DECREMENT;//The elevator has been dragged to a new position.
// Public Constructors
public Scrollbar();
public Scrollbar(int orientation);//ScrollBarOrientation could be ScrollBar.HORIZONTAL or ScrollBar.VERTICAL
public Scrollbar(int orientation, int value, int visible, int minimum,int maximum);//ScrollBarOrientation could be ScrollBar.HORIZONTAL or ScrollBar.VERTICAL startingPosition is th eint value where the slider will start last two argument will specify the minimum and maximum range.
// Constants
public static final int HORIZONTAL;
public static final int VERTICAL;
// Public Instance Methods
public synchronized void addAdjustmentListener(AdjustmentListener l);
// From Adjustable
public void addNotify(); // Overrides Component
public int getBlockIncrement(); // From Adjustable
public int getLineIncrement();
public int getMaximum(); // From Adjustable
public int getMinimum(); // From Adjustable
public int getOrientation(); // From Adjustable
public int getPageIncrement();
public int getUnitIncrement(); // From Adjustable
public int getValue(); // From Adjustable returns position of the scroll relative to min and max
public int getVisible();
public int getVisibleAmount(); // From Adjustable
public void removeAdjustmentListener(AdjustmentListener l);// From Adjustable
public synchronized void setBlockIncrement(int v); // From Adjustable sets how much to move on page by one click up down increment
public void setLineIncrement(int v);//sets how much to move on page by one click
public synchronized void setMaximum(int newMaximum); // From Adjustable
public synchronized void setMinimum(int newMinimum); // From Adjustable
public synchronized void setOrientation(int orientation);
public void setPageIncrement(int v);//sets how much to move on page by one click
public synchronized void setUnitIncrement(int v); // From Adjustable sets how much to move on page by one click
public synchronized void setValue(int newValue); // From Adjustable sets the position of the slider to the value n
public synchronized void setValues(int value, int visible, int minimum,int maximum);//sets the parameters of the slider
public synchronized void setVisibleAmount(int newAmount); // From Adjustable
// Protected Instance Methods
protected String paramString(); // Overrides Component
protected void processAdjustmentEvent(AdjustmentEvent e);
protected void processEvent(AWTEvent e); // Overrides Component
} 

The details of the class structure are given as follows:

public final static int HORIZONTAL;

public final static int HORIZONTAL represents a constant that is used for a Scrollbar with a horizontal orientation.

public final static int VERTICAL;

public final static int VERTICAL represents a constant used for a Scrollbar with a vertical orientation.

public Scrollbar();

public Scrollbar() constructs a vertical Scrollbar object; slider size, minimum value, maximum value, and initial value are all zero.

public Scrollbar(int orientation);

public Scrollbar(int orientation) constructs a Scrollbar object, in the designated direction; slider size, minimum value, maximum value, and initial value are all zero.

Parameter
orientation – Scrollbar constant designating direction.

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

public Scrollbar(int orientation, int value, int visible, int minimum,int maximum) constructs a Scrollbar object with the given values.

Parameter
orientation – Scrollbar constant designating direction.
value – Initial value of Scrollbar.
visible – Initial slider size.
minimum – Initial minimum value.
maximum – Initial maximum value.

public void addAdjustmentListener (AdjustmentListener l);

public void addAdjustmentListener (AdjustmentListener l) method adds a listener for adjustment event.

Parameter
l – An object that implements the AdjustmentListener interface.

public void addNotify();

public void addNotify() method creates Scrollbar’s peer.

public int getBlockIncrement();

public int getBlockIncrement() method returns the amount to scroll when a paging area is selected.

This method returns the amount to scroll when a paging area is selected.

public int getLineIncrement();

public int getLineIncrement() method returns The amount to scroll when one of the arrows at the ends of the scrollbar is selected. This method is now replaced by getUnitIncrement().

This method returns The amount to scroll when one of the arrows at the ends of the scrollbar is selected.

public int getMaximum();

public int getMaximum() method returns the maximum value that the Scrollbar can take.

This method returns the maximum value that the Scrollbar can take.

public int getMinimum();

public int getMinimum() method returns the minimum value that the Scrollbar can take.

This method returns the minimum value that the Scrollbar can take.

public int getOrientation();

public int getOrientation() method returns a constant representing the direction of the Scrollbar.

This method returns a constant representing the direction of the Scrollbar.

public int getPageIncrement();

public int getPageIncrement() method returns the amount to scroll when a paging area is selected. Replaced with getBlockIncrement().

This method returns the amount to scroll when a paging area is selected. Replaced with getBlockIncrement().

public int getUnitIncrement();

public int getUnitIncrement() method returns the amount to scroll when one of the arrows at the ends of the scrollbar is selected.

This method returns the amount to scroll when one of the arrows at the ends of the scrollbar is selected.

Don't miss out!
Subscribe To Newsletter

Receive top technical news, lesson ideas, travel tips and more!

Invalid email address
Give it a try. You can unsubscribe at any time.

Spread the love
  • 28
  • 34
  • 56
  • 35
  •  
  •  
  •  
  • 12
  •  
  •  
    165
    Shares

LEAVE A REPLY

Please enter your comment!
Please enter your name here