Creating Scrollbars in an Applet Window using Advanced Java Programming

Home  »  Java  »  Advance Java »    Java AWT (Abstract Window ToolKit) »    Scrollbars

Scrollbars are components that enable a value to be selected by sliding a box between two arrows. Several components have built-in scrollbar functionality, including text areas and scrolling lists. The Scrollbar class is used for creating scrollbars. A scrollbar can be horizontal or vertical.

  1. Scrollbar() Here the maximum and minimum value of scrollbar is 0
  2. Scrollbar(int) It creates a scrollbar with minimum and maximum value as 0 but with its orientation either vertical or horizontal.
  3. Scrollbar(int, int, int, int) It creates a scrollbar in which ,first argument Specify the orientation , then the width or height of the box which appears in the Scrollbar and then its minimum and then its maximum value.
For ex:-
Scrollbar bar=new scrollbar (Scrollbar. VERTICAL ,10,0,1,100);
add(bar);

Here Scrollbar. VERTICAL Specify the Orientation and 10 Specify the Width and Height of Box of Scrollbar and 0 is the Starting value and 1 is Minimum value and 100 is the Maximum value of Scrollbar.

The following program code show how to create a frame window:

The above code will be stored in the file called Scroll.java, which on compilation will crate a class file called Scroll.class. Now compiple this file using below commands in the DOS mode:

C:\>jdk1.4\bin>javac Scroll.java
C:\>jdk1.4\bin>appletviewer Scroll.java


"Output of Scroll.java"


Download Complete Program

  -  



Methods of a Scrollbar
Method
Action
getValue()Used to get the value of Scrollbar
setValue (int)Used to set the Value of Scrollbar.



AWT Controls



Label Buttons Check Boxes Radio Buttons
Choice Controls TextFields & Password TextAreas Scrolling Lists Scrollbars




No comments:

Post a Comment