Java AWT Scrollbar Tutorial

Scrollbar in Java AWT with example: This java tutorial is used to design a basic & simple scrollbar. This option can makes an ease of work. This program can be used for students lab exercises and many. It is a free source code. Anyone can use, without cost. Example program is given at the bottom.

SCROLLBAR IN JAVA

This java program will reduce the need of window size in the screen. If you are creating more than a page, then it is not possible to display in one page. So we can see the text by scrolling. The scroll gets done by using the keys of up and down arrows or mouse pointer to see the text.

[Useful: C Program Tutorials] & [IT Companies Details]

Scrollbar Tutorial:

Q: Write a Java code for creating Scrollbar using AWT example.

//Import statements
import java.awt.*;
import java.awt.event.*;
//Class definition
class ScrollbarDemo extends Frame implements AdjustmentListener
{
	//Variable declaration
	Scrollbar sc;
	TextField tc;
// © http://students3k.com – Karthikh Venkat
public ScrollbarDemo()
{	setTitle("Students3k Scroll Bar");
	sc=new Scrollbar(Scrollbar.HORIZONTAL);
	sc.addAdjustmentListener(this);
	tc=new TextField(10);
	add("South",sc);
	add("North",tc);
	setBackground(Color.pink);
	setSize(300,300);
	show();
}
public void adjustmentValueChanged(AdjustmentEvent e)
{
	tc.setText(String.valueOf(s.getValue()));
}
// © http://students3k.com – Karthikh Venkat
public static void main(String args[])
 {
   	 new ScrollbarDemo();
 }
}

SEE: All Examination Results & News