gamelan
Search EarthWeb
CodeGuru | Gamelan | Jars | Wireless | Discussions
Navigate developer.com
Architecture & Design  
Database  
Java
Languages & Tools
Microsoft & .NET
Open Source  
Project Management  
Security  
Techniques  
Voice  
Web Services  
Wireless/Mobile
XML  
New
 
Technology Jobs  

   Developer.com Webcasts:
  The Impact of Coding Standards and Code Reviews

  Project Management for the Developer

  Defining Your Own Software Development Methodology

  more Webcasts...




Vote for the Developer.com Product of the Year Winners!




Developer Jobs

Be a Commerce Partner














 


Developer News -
Red Hat Fedora Claims It's the Leader in Linux    November 21, 2008
Dos and Don'ts of SOA Data Access    November 20, 2008
Mandrake Linux Founder Back, Virtually    November 20, 2008
Amazon: We're a Technology Company    November 19, 2008
Free Tech Newsletter -

SWT Programming with Eclipse
By Koray Guclu

Go to page: Prev  1  2  3  4  5  6  Next  

8.2.2. Slider, Scale, and ProgressBar widgets

Scale represents a range of selectable continues values. The range can be specified by the setMinimum() and setMaximum() methods of the Scale class. You can get the selection value by using the getSelection() method. A scale can only have one selected value at a given time. That is to say, it is not possible to have multiple selections.

Figure 6. Slider and Scale widgets inside a Group.

Depending on the parameters passed to the constractor, it is possible to create different scale and slider widgets. The slider and scale constants are shown in Table 5.

Table 5. SWT slider & scale style bar constants
SWT.HORIZONTAL
SWT.VERTICAL
Shows horizontal or vertical widget

Optionally, you can use the SWT.BORDER constant to create a border around a scale widget. This constant has no effect on the slider widget.

 Source 4. Slider widget example
 final Slider slider =
   new Slider(shell,SWT.VERTICAL);
 slider.setMinimum(0);
 slider.setMaximum(100);
 slider.setIncrement(5);
 slider.setPageIncrement(10);
 slider.setSelection(25);
 slider.addSelectionListener(
  new SelectionAdapter()
  {
    public void widgetSelected(SelectionEvent e)
    {
      System.out.println("Selection:"+
                          slider.getSelection());
    }
  }
 );

The ProgressBar widget is similar to the Slider and Scale widgets, but it is not selectable. It shows the progress of a task. You can use the SWT.SMOOTH and SWT.INTERMINATE constants with the ProgressBar widget.

8.2.3. Text widget

A Text widget can be used to show or to edit text. Alternatively, you can use a StyledText widget to display the text by using a different font and color. The StyledText widget allows you to set the foreground, background color, and font for a given range within a text block.

Figure 7. Text widget.

It is possible to create a Text widget with the constants shown in Table 6. A Text widget is a scrollable widget. Therefore, the SWT.H_SCROLL and SWT.V_SCROLL constants can be used to add scroll bars to a Text widget.

Table 6. SWT Text style bit constants
SWT.MULTI
SWT.SINGLE
Shows a single line or multi line widget
SWT.READ_ONLY Creates a read-only widget
SWT.WRAP Wraps the text

Source 5 is a simple Text widget usage example.

Source 5. Text widget example
 Text text =
   new Text(shell, SWT.MULTI|SWT.WRAP);
8.2.4. List widget

A List widget can be used to display a list of selectable string values. In the case of a selection, the List object sends a notification event to its listeners. The type of a selection can be single or multiple selections. The type of the selection is determined by the SWT.SINGLE or SWT.MULTI constants. The List widget is a scrollable widget. Therefore, the SWT.H_SCROLL and SWT.V_SCROLL constants can be used to add scroll bars to a Text widget.

Figure 8. List widget.

The following code snippet shows a simple List widget example.

Source 6. List example
 final List list = new List(shell,SWT.MULTI);
 for (int i = 1; i < 11; i++) 
 {
   list.add(i+".)www.korayguclu.de");
 }
 list.addSelectionListener(
   new SelectionAdapter()
   {
     public void widgetSelected(SelectionEvent e)
     {
       List list = (List) e.getSource();
       String[] str = list.getSelection();
       for (int i = 0; i < str.length; i++)
       {
         System.out.println("Selection: "+str[i]);
       }
     }
  }
 );
8.2.5. Sash widget

A Sash widget can be used to display composite widgets in resizable areas. The following figure shows a Sash widget example.

Figure 9. Sash widget.

A basic sash example can be seen below.

Source 7. Sash example
 Button button = new Button(shell,SWT.PUSH);
 Sash sash = new Sash(shell, SWT.VERTICAL);
 Button button1 = new Button(shell,SWT.PUSH);

Go to page: Prev  1  2  3  4  5  6  Next  

Previous article: A First Look at Eclipse Plug-In Programming
Next article: Constructing SWT Layouts


Tools:
Add www.developer.com to your favorites
Add www.developer.com to your browser search box
IE 7 | Firefox 2.0 | Firefox 1.5.x
Receive news via our XML/RSS feed


Other Java Archives






internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers