Home Tutorials Swt Create Radio Buttons in SWT

Related Tutorials


 
 

Share on Google+Share on Google+

Create Radio Buttons in SWT

Advertisement
In SWT, the style RADIO defined in the Button class allows to create radio button. We have create an array object of Button class. The class Label displays the specified string.

Create Radio Buttons in SWT

     

This section illustrates you how to create radio button.

In SWT, the style RADIO defined in the Button class allows to create radio button. We have create an array object of Button class. The class Label displays the specified string. The method label.setText() sets the string specified. The setBounds() sets the location.

The method radioButton[].setSelection(true) sets the selection state.

Here is the code of RadioButtonExample.java

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

public class RadioButtonExample {

  public static void main(String[] args) {
  final Display display = new Display();
  Shell shell = new Shell(display);
  shell.setText("Radio Buttons");
  shell.pack();
 
  final Label label = new Label(shell, SWT.NONE);
  label.setText("Which programming language you like most");
  label.setBounds(10517030);
  final Button radioButton1 = new Button(shell, SWT.RADIO);
  radioButton1.setText("Java");
  radioButton1.setBounds(10307530);
  
  final Button radioButton2 = new Button(shell, SWT.RADIO);
  radioButton2.setText("C/C++");
  radioButton2.setBounds(10557530);
  
  final Button radioButton3 = new Button(shell, SWT.RADIO);
  radioButton3.setText(".NET");
  radioButton3.setBounds(10807530);
  
  final Button radioButton4 = new Button(shell, SWT.RADIO);
  radioButton4.setText("PHP");
  radioButton4.setBounds(101057530);
  
  shell.open();
  shell.pack();
  while (!shell.isDisposed()) {
  if (!display.readAndDispatch())
  display.sleep();
  }
  display.dispose();
  }
}

Output will be displayed as:

Download Source Code

     

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



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

Related Tutorials

Discuss: Create Radio Buttons in SWT   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:1
xyz
July 4, 2011
how to create multiple radio buttons?

can we add multiple radio buttons to tree with vertical scroll bar?
DMCA.com