Java/SWT JFace Eclipse/Group

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

Demonstrates groups

//Send questions, comments, bug reports, etc. to the authors:
//Rob Warner (rwarner@interspatial.ru)
//Robert Harris (rbrt_harris@yahoo.ru)
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
/**
 * This class demonstrates groups
 */
public class GroupExample {
  public static void main(String[] args) {
    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("John");
    new Button(group1, SWT.RADIO).setText("Paul");
    new Button(group1, SWT.RADIO).setText("George");
    new Button(group1, SWT.RADIO).setText("Ringo");
    // 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("Barry");
    new Button(group2, SWT.RADIO).setText("Robin");
    new Button(group2, SWT.RADIO).setText("Maurice");
    
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }
    display.dispose();
  }
}





Group Example

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
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 GroupShellExample {
  Display d;
  Shell s;
  GroupShellExample() {
    d = new Display();
    s = new Shell(d);
    s.setSize(200, 200);
    
    s.setText("A Shell Composite Example");
    final 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();
  }
  public static void main(String[] arg) {
    new GroupShellExample();
  }
}
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";
  }
}





Group Example 2

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
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 GroupShellExample2 {
  Display d;
  Shell s;
  GroupShellExample2() {
    d = new Display();
    s = new Shell(d);
    s.setSize(200, 200);
    
    s.setText("A Group Example");
    final Group g = new Group(s, SWT.SHADOW_ETCHED_IN);
    g.setSize(110, 75);
    g.setText("Options Group");
    final Button b1;
    final Button b2;
    final Button b3;
    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");
    g.pack();
    g.setLocation(20, 20);
    s.open();
    while (!s.isDisposed()) {
      if (!d.readAndDispatch())
        d.sleep();
    }
    d.dispose();
  }
  public static void main(String[] arg) {
    new GroupShellExample2();
  }
}





Group Examples

/******************************************************************************
 * All Right Reserved. 
 * Copyright (c) 1998, 2004 Jackwind Li Guojie
 * 
 * Created on 2004-4-10 18:41:39 by JACK
 * $Id$
 * 
 *****************************************************************************/

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
public class GroupExamples {
  Display display = new Display();
  Shell shell = new Shell(display);
  public GroupExamples() {
    
    Group group0 = new Group(shell, SWT.NULL);
    group0.setLayout(new FillLayout());
    Label label = new Label(group0, SWT.NULL);
    label.setAlignment(SWT.CENTER);
    label.setText("a group without title.");
    
    Group group1 = new Group(shell, SWT.NULL);
    group1.setText("SWT.NULL");
    
    Group group2 = new Group(shell, SWT.SHADOW_ETCHED_IN);
    group2.setText("SWT.SHADOW_ETCHED_IN");  
    Group group3 = new Group(shell, SWT.SHADOW_ETCHED_OUT);
    group3.setText("SWT.SHADOW_ETCHED_OUT");    
    
    Group group4 = new Group(shell, SWT.SHADOW_IN);
    group4.setText("SWT.SHADOW_IN");  
    
    Group group5 = new Group(shell, SWT.SHADOW_OUT);
    group5.setText("SWT.SHADOW_OUT");
    
    
    Group[] groups = new Group[]{group0, group1, group2, group3, group4, group5};
    
    for(int i=0; i<groups.length; i++) {
      groups[i].setBounds(10, 10 + i * 50, 300, 40);
    }
    shell.pack();
    shell.open();
    //textUser.forceFocus();
    // Set up the event loop.
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        // If no more entries in event queue
        display.sleep();
      }
    }
    display.dispose();
  }
  private void init() {
  }
  public static void main(String[] args) {
    new GroupExamples();
  }
}





Group Label and Button

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.ruposite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
public class Ch3_Composite extends Composite {
  public Ch3_Composite(Composite parent) {
    super(parent, SWT.NONE);
    parent.getShell().setText("Chapter 3 Composite");
    Ch3_Group cc1 = new Ch3_Group(this);
    cc1.setLocation(0, 0);
    cc1.pack();
    Ch3_SashForm cc2 = new Ch3_SashForm(this);
    cc2.setLocation(125, 25);
    cc2.pack();
    pack();
  }
}
class Ch3_Group extends Composite {
  public Ch3_Group(Composite parent) {
    super(parent, SWT.NONE);
    Group group = new Group(this, SWT.SHADOW_ETCHED_IN);
    group.setText("Group Label");
    Label label = new Label(group, SWT.NONE);
    label.setText("Two buttons:");
    label.setLocation(20, 20);
    label.pack();
    Button button1 = new Button(group, SWT.PUSH);
    button1.setText("Push button");
    button1.setLocation(20, 45);
    button1.pack();
    Button button2 = new Button(group, SWT.CHECK);
    button2.setText("Check button");
    button2.setBounds(20, 75, 90, 30);
    group.pack();
  }
}
class Ch3_SashForm extends Composite {
  public Ch3_SashForm(Composite parent) {
    super(parent, SWT.NONE);
    SashForm sf = new SashForm(this, SWT.VERTICAL);
    sf.setSize(120, 80);
    Button button1 = new Button(sf, SWT.ARROW | SWT.UP);
    button1.setSize(120, 40);
    Button button2 = new Button(sf, SWT.ARROW | SWT.DOWN);
    button2.setBounds(0, 40, 120, 40);
  }
}





SWT Group demo

import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.ruposite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
public class CompViewer extends ApplicationWindow {
  public CompViewer() {
    super(null);
  }
  protected Control createContents(Composite parent) {
    Ch3_Group cc1 = new Ch3_Group(parent);
    return parent;
  }
  public static void main(String[] args) {
    CompViewer cv = new CompViewer();
    cv.setBlockOnOpen(true);
    cv.open();
    Display.getCurrent().dispose();
  }
}
class Ch3_Group extends Composite {
  public Ch3_Group(Composite parent) {
    super(parent, SWT.NONE);
    Group group = new Group(this, SWT.SHADOW_ETCHED_IN);
    group.setText("Group Label");
    Label label = new Label(group, SWT.NONE);
    label.setText("Two buttons:");
    label.setLocation(20, 20);
    label.pack();
    Button button1 = new Button(group, SWT.PUSH);
    button1.setText("Push button");
    button1.setLocation(20, 45);
    button1.pack();
    Button button2 = new Button(group, SWT.CHECK);
    button2.setText("Check button");
    button2.setBounds(20, 75, 90, 30);
    group.pack();
  }
}