Java by API/org.eclipse.swt.widgets/Group

Материал из Java эксперт
Перейти к: навигация, поиск

new Group(Composite parent, int style)

   <source lang="java">

import org.eclipse.swt.SWT; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.ruposite; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Shell; public class MainClass {

 public static void main(String[] a) {
   Display d = new Display();
   Shell s = new Shell(d);
   s.setText("A Shell Composite Example");
   GroupExample ge = new GroupExample(s, SWT.SHADOW_ETCHED_IN);
   ge.setLocation(20, 20);
   s.open();
   while (!s.isDisposed()) {
     if (!d.readAndDispatch())
       d.sleep();
   }
   d.dispose();
 }

} class GroupExample extends Composite {

 final Button b1;
 final Button b2;
 final Button b3;
 public GroupExample(Composite c, int style) {
   super(c, SWT.NO_BACKGROUND);
   this.setSize(110, 75);
   this.setLayout(new FillLayout());
   final Group g = new Group(this, style);
   g.setSize(110, 75);
   g.setText("Options Group");
   b1 = new Button(g, SWT.RADIO);
   b1.setBounds(10, 20, 75, 15);
   b1.setText("Option One");
   b2 = new Button(g, SWT.RADIO);
   b2.setBounds(10, 35, 75, 15);
   b2.setText("Option Two");
   b3 = new Button(g, SWT.RADIO);
   b3.setBounds(10, 50, 80, 15);
   b3.setText("Option Three");
 }
 public String getSelected() {
   if (b1.getSelection())
     return "Option One";
   if (b2.getSelection())
     return "Option Two";
   if (b3.getSelection())
     return "Option Three";
   return "None Selected";
 }

}

      </source>
   
  
 
  



new Group(Shell shell, SWT.NO_RADIO_GROUP)

   <source lang="java">

import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.layout.RowLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Shell; public class MainClass {

 public static void main(String[] a) {
   Display display = new Display();
   Shell shell = new Shell(display);
   shell.setLayout(new GridLayout());
   // Create the first group
   Group group1 = new Group(shell, SWT.SHADOW_IN);
   group1.setText("Who"s your favorite?");
   group1.setLayout(new RowLayout(SWT.VERTICAL));
   new Button(group1, SWT.RADIO).setText("A");
   new Button(group1, SWT.RADIO).setText("B");
   new Button(group1, SWT.RADIO).setText("C");
   new Button(group1, SWT.RADIO).setText("D");
   // Create the second group
   Group group2 = new Group(shell, SWT.NO_RADIO_GROUP);
   group2.setText("Who"s your favorite?");
   group2.setLayout(new RowLayout(SWT.VERTICAL));
   new Button(group2, SWT.RADIO).setText("1");
   new Button(group2, SWT.RADIO).setText("2");
   new Button(group2, SWT.RADIO).setText("3");
   shell.open();
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) {
       display.sleep();
     }
   }
   display.dispose();
 }

}

      </source>