Home Tutorials Swt Use Group Class in SWT
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

Use Group Class in SWT

Advertisement
In this section, you will learn how to use Group class.

Use Group Class in SWT

     

In this section, you will learn how to use Group class.

In SWT, the class Group of package org.eclipse.swt.widgets provides an etched border with an optional title. In the given example, we have create two groups by using the class Group. In the first group, we have create check boxes and in the second group, radio buttons are defined.

Here is the code of GroupExample.java

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

public class GroupExample {
  public static void main(String[] args) {
  Display display = new Display();
  Shell shell = new Shell(display);
  shell.setLayout(new GridLayout());
  shell.setText("Show Group");
  shell.setSize(200,250);
  Group group1 = new Group(shell, SWT.SHADOW_IN);
  group1.setText("Which are your favourite sports?");
  group1.setLayout(new RowLayout(SWT.VERTICAL));
  new Button(group1, SWT.CHECK).setText("Tennis");
  new Button(group1, SWT.CHECK).setText("FootBall");
  new Button(group1, SWT.CHECK).setText("Cricket");
  new Button(group1, SWT.CHECK).setText("Hockey");
  
  Group group2 = new Group(shell, SWT.SHADOW_IN);
  group2.setText("Where is Taj Mahal?");
  group2.setLayout(new RowLayout(SWT.VERTICAL));
  new Button(group2, SWT.RADIO).setText("Lucknow");
  new Button(group2, SWT.RADIO).setText("Agra");
  new Button(group2, SWT.RADIO).setText("Delhi");
  new Button(group2, SWT.RADIO).setText("Mumbai");

  shell.open();
  while (!shell.isDisposed()) {
  if (!display.readAndDispatch()) {
  display.sleep();
  }
  }
  display.dispose();
  }

Output will be displayed as:

Download Source Code

     

Advertisement

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: October 3, 2008

Ask Questions?    Discuss: Use Group Class in SWT  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com