Home Tutorials Swt Use Group Class in SWT



Use Group Class in SWT
Posted on: October 3, 2008 at 12:00 AM
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

     

Related Tags for Use Group Class in SWT:
ceclipseideclassbuttonioswtgetipwidgetsorderviwidgetusingcliborderthisidpackageradcreatecheckgroupbuttonsdefineexampletitleboxgroupswithradiotolearnexamoptioneareilitdesupssectionliusefirstinasmpsoptionalpackadclesagehowproackdefinedxaxampsxeclipatpackisirhallivmpletchetchgetseaandarwidwttttwssrdthswcondavstecletcfinetcorgpleplprndono


More Tutorials from this section

Ask Questions?    Discuss: Use Group Class in 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.