Home Tutorials Swt Create Scroll Bar in Java using SWT



Create Scroll Bar in Java using SWT
Posted on: October 4, 2008 at 12:00 AM
The given example will show you how to create scroll bar in Java using SWT, for that we have created a class with the name ScrollBarExamle that imports a package org.eclipse.swt.widgets, which is used to create ScrollBar in Java.

Create Scroll Bar in Java using SWT

     

This section is all about creating scroll bar in Java SWT 

The given example will show you how to create scroll bar in Java using SWT, for that we have created a class with the name ScrollBarExamle that imports a package org.eclipse.swt.widgets, which is used to create ScrollBar in Java. Further in this example, we have create a list by using the class List. A string is added to the list by using the method list.add(). We have create a for loop to print the specified string 20 times.

The styles  SWT.V_SCROLL, SWT.H_SCROLL provided by the class ScrollBar creates the vertical and horizontal bars.

Here is the code of ScrollBarExample.java

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

public class ScrollBarExample {
  public static void main(String[] args) {
  Display display = new Display();
  Shell shell = new Shell(display);
  shell.setLayout(new FillLayout());
  
  List list = new List(shell,SWT.V_SCROLL|SWT.H_SCROLL);
  for (int i = 0; i < 20; i++) {
  list.add("Java is an Object Oriented Programming Language");
  }
  shell.setText("Show Scrollbar");
  shell.open();
  shell.setSize(200,150);
  while (!shell.isDisposed()) {
  if (!display.readAndDispatch()) {
  display.sleep();
  }
  }
  display.dispose();
  }
}

Output will be displayed as:

Download Source Code

     

Related Tags for Create Scroll Bar in Java using SWT:
javaceclipsestringoopxamlclasslisttimeimportioswtmethodsedprintgetloopscrollbaripwidgetsportscrollnamewidgetusingcliintthisidpackageoocreateshowifforieexampleaddwithtoexamciportssheilitbarsectionliusepeimddeinmlasmntoutpstrddjpackadclesspecallagemehowackcreatingxawhichxampsspcreatedclipataddedpackimportsishaimellivmplgetseaarstrrtrtswidwtvascrssriringthshoswavbarestabatihateclorgpleplpronolo


More Tutorials from this section

Ask Questions?    Discuss: Create Scroll Bar in Java using SWT  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.