Java by API/org.eclipse.swt/SWT — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 14:33, 31 мая 2010
Содержание
- 1 SWT.ARROW | SWT.LEFT
- 2 SWT.ARROW | SWT.LEFT | SWT.BORDER
- 3 SWT.ARROW | SWT.LEFT | SWT.FLAT
- 4 SWT.CHECK | SWT.BORDER
- 5 SWT.CHECK | SWT.FLAT
- 6 SWT.CR
- 7 SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL
- 8 SWT.ESC
- 9 SWT.NO
- 10 SWT.RADIO
- 11 SWT.RADIO | SWT.BORDER
- 12 SWT.SHADOW_ETCHED_IN
- 13 SWT.TOGGLE | SWT.BORDER
- 14 SWT.TOGGLE | SWT.FLAT
- 15 SWT.YES
SWT.ARROW | SWT.LEFT
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
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.Label;
public class MainClass extends ApplicationWindow {
public MainClass() {
super(null);
}
public static void main(String[] args) {
ApplicationWindow w = new MainClass();
w.setBlockOnOpen(true);
w.open();
Display.getCurrent().dispose();
}
protected Control createContents(Composite parent) {
Composite container = new Composite(parent, SWT.NULL);
this.getShell().setText("ButtonTest");
GridLayout layout = new GridLayout();
container.setLayout(layout);
layout.numColumns = 4;
layout.verticalSpacing = 9;
Label label;
label = new Label(container, SWT.NONE);
label.setText("Button Type");
label = new Label(container, SWT.NONE);
label.setText("NONE");
label = new Label(container, SWT.NONE);
label.setText("BORDER");
label = new Label(container, SWT.NONE);
label.setText("FLAT");
createLabel(container, SWT.NONE, "Push");
createButton(container, SWT.PUSH, "button1");
createButton(container, SWT.BORDER, "button2");
createButton(container, SWT.FLAT, "button3");
createLabel(container, SWT.NONE, "Radio");
createButton(container, SWT.RADIO, "button1");
createButton(container, SWT.RADIO | SWT.BORDER, "button2");
createButton(container, SWT.RADIO | SWT.FLAT, "button3");
createLabel(container, SWT.NONE, "Toggle");
createButton(container, SWT.TOGGLE, "button1");
createButton(container, SWT.TOGGLE | SWT.BORDER, "button2");
createButton(container, SWT.TOGGLE | SWT.FLAT, "button3");
createLabel(container, SWT.NONE, "Check");
createButton(container, SWT.CHECK, "button1");
createButton(container, SWT.CHECK | SWT.BORDER, "button2");
createButton(container, SWT.CHECK | SWT.FLAT, "button3");
createLabel(container, SWT.NONE, "Arrow | Left");
createButton(container, SWT.ARROW | SWT.LEFT, "button1");
createButton(container, SWT.ARROW | SWT.LEFT | SWT.BORDER, "button2");
createButton(container, SWT.ARROW | SWT.LEFT | SWT.FLAT, "button3");
return container;
}
public void createButton(Composite c, int style, String text) {
Button b = new Button(c, style);
b.setText(text);
}
public void createLabel(Composite c, int style, String text) {
Label l = new Label(c, style);
l.setText(text);
}
}
SWT.ARROW | SWT.LEFT | SWT.BORDER
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
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.Label;
public class MainClass extends ApplicationWindow {
public MainClass() {
super(null);
}
public static void main(String[] args) {
ApplicationWindow w = new MainClass();
w.setBlockOnOpen(true);
w.open();
Display.getCurrent().dispose();
}
protected Control createContents(Composite parent) {
Composite container = new Composite(parent, SWT.NULL);
this.getShell().setText("ButtonTest");
GridLayout layout = new GridLayout();
container.setLayout(layout);
layout.numColumns = 4;
layout.verticalSpacing = 9;
Label label;
label = new Label(container, SWT.NONE);
label.setText("Button Type");
label = new Label(container, SWT.NONE);
label.setText("NONE");
label = new Label(container, SWT.NONE);
label.setText("BORDER");
label = new Label(container, SWT.NONE);
label.setText("FLAT");
createLabel(container, SWT.NONE, "Push");
createButton(container, SWT.PUSH, "button1");
createButton(container, SWT.BORDER, "button2");
createButton(container, SWT.FLAT, "button3");
createLabel(container, SWT.NONE, "Radio");
createButton(container, SWT.RADIO, "button1");
createButton(container, SWT.RADIO | SWT.BORDER, "button2");
createButton(container, SWT.RADIO | SWT.FLAT, "button3");
createLabel(container, SWT.NONE, "Toggle");
createButton(container, SWT.TOGGLE, "button1");
createButton(container, SWT.TOGGLE | SWT.BORDER, "button2");
createButton(container, SWT.TOGGLE | SWT.FLAT, "button3");
createLabel(container, SWT.NONE, "Check");
createButton(container, SWT.CHECK, "button1");
createButton(container, SWT.CHECK | SWT.BORDER, "button2");
createButton(container, SWT.CHECK | SWT.FLAT, "button3");
createLabel(container, SWT.NONE, "Arrow | Left");
createButton(container, SWT.ARROW | SWT.LEFT, "button1");
createButton(container, SWT.ARROW | SWT.LEFT | SWT.BORDER, "button2");
createButton(container, SWT.ARROW | SWT.LEFT | SWT.FLAT, "button3");
return container;
}
public void createButton(Composite c, int style, String text) {
Button b = new Button(c, style);
b.setText(text);
}
public void createLabel(Composite c, int style, String text) {
Label l = new Label(c, style);
l.setText(text);
}
}
SWT.ARROW | SWT.LEFT | SWT.FLAT
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
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.Label;
public class MainClass extends ApplicationWindow {
public MainClass() {
super(null);
}
public static void main(String[] args) {
ApplicationWindow w = new MainClass();
w.setBlockOnOpen(true);
w.open();
Display.getCurrent().dispose();
}
protected Control createContents(Composite parent) {
Composite container = new Composite(parent, SWT.NULL);
this.getShell().setText("ButtonTest");
GridLayout layout = new GridLayout();
container.setLayout(layout);
layout.numColumns = 4;
layout.verticalSpacing = 9;
Label label;
label = new Label(container, SWT.NONE);
label.setText("Button Type");
label = new Label(container, SWT.NONE);
label.setText("NONE");
label = new Label(container, SWT.NONE);
label.setText("BORDER");
label = new Label(container, SWT.NONE);
label.setText("FLAT");
createLabel(container, SWT.NONE, "Push");
createButton(container, SWT.PUSH, "button1");
createButton(container, SWT.BORDER, "button2");
createButton(container, SWT.FLAT, "button3");
createLabel(container, SWT.NONE, "Radio");
createButton(container, SWT.RADIO, "button1");
createButton(container, SWT.RADIO | SWT.BORDER, "button2");
createButton(container, SWT.RADIO | SWT.FLAT, "button3");
createLabel(container, SWT.NONE, "Toggle");
createButton(container, SWT.TOGGLE, "button1");
createButton(container, SWT.TOGGLE | SWT.BORDER, "button2");
createButton(container, SWT.TOGGLE | SWT.FLAT, "button3");
createLabel(container, SWT.NONE, "Check");
createButton(container, SWT.CHECK, "button1");
createButton(container, SWT.CHECK | SWT.BORDER, "button2");
createButton(container, SWT.CHECK | SWT.FLAT, "button3");
createLabel(container, SWT.NONE, "Arrow | Left");
createButton(container, SWT.ARROW | SWT.LEFT, "button1");
createButton(container, SWT.ARROW | SWT.LEFT | SWT.BORDER, "button2");
createButton(container, SWT.ARROW | SWT.LEFT | SWT.FLAT, "button3");
return container;
}
public void createButton(Composite c, int style, String text) {
Button b = new Button(c, style);
b.setText(text);
}
public void createLabel(Composite c, int style, String text) {
Label l = new Label(c, style);
l.setText(text);
}
}
SWT.CHECK | SWT.BORDER
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
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.Label;
public class MainClass extends ApplicationWindow {
public MainClass() {
super(null);
}
public static void main(String[] args) {
ApplicationWindow w = new MainClass();
w.setBlockOnOpen(true);
w.open();
Display.getCurrent().dispose();
}
protected Control createContents(Composite parent) {
Composite container = new Composite(parent, SWT.NULL);
this.getShell().setText("ButtonTest");
GridLayout layout = new GridLayout();
container.setLayout(layout);
layout.numColumns = 4;
layout.verticalSpacing = 9;
Label label;
label = new Label(container, SWT.NONE);
label.setText("Button Type");
label = new Label(container, SWT.NONE);
label.setText("NONE");
label = new Label(container, SWT.NONE);
label.setText("BORDER");
label = new Label(container, SWT.NONE);
label.setText("FLAT");
createLabel(container, SWT.NONE, "Push");
createButton(container, SWT.PUSH, "button1");
createButton(container, SWT.BORDER, "button2");
createButton(container, SWT.FLAT, "button3");
createLabel(container, SWT.NONE, "Radio");
createButton(container, SWT.RADIO, "button1");
createButton(container, SWT.RADIO | SWT.BORDER, "button2");
createButton(container, SWT.RADIO | SWT.FLAT, "button3");
createLabel(container, SWT.NONE, "Toggle");
createButton(container, SWT.TOGGLE, "button1");
createButton(container, SWT.TOGGLE | SWT.BORDER, "button2");
createButton(container, SWT.TOGGLE | SWT.FLAT, "button3");
createLabel(container, SWT.NONE, "Check");
createButton(container, SWT.CHECK, "button1");
createButton(container, SWT.CHECK | SWT.BORDER, "button2");
createButton(container, SWT.CHECK | SWT.FLAT, "button3");
createLabel(container, SWT.NONE, "Arrow | Left");
createButton(container, SWT.ARROW | SWT.LEFT, "button1");
createButton(container, SWT.ARROW | SWT.LEFT | SWT.BORDER, "button2");
createButton(container, SWT.ARROW | SWT.LEFT | SWT.FLAT, "button3");
return container;
}
public void createButton(Composite c, int style, String text) {
Button b = new Button(c, style);
b.setText(text);
}
public void createLabel(Composite c, int style, String text) {
Label l = new Label(c, style);
l.setText(text);
}
}
SWT.CHECK | SWT.FLAT
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
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.Label;
public class MainClass extends ApplicationWindow {
public MainClass() {
super(null);
}
public static void main(String[] args) {
ApplicationWindow w = new MainClass();
w.setBlockOnOpen(true);
w.open();
Display.getCurrent().dispose();
}
protected Control createContents(Composite parent) {
Composite container = new Composite(parent, SWT.NULL);
this.getShell().setText("ButtonTest");
GridLayout layout = new GridLayout();
container.setLayout(layout);
layout.numColumns = 4;
layout.verticalSpacing = 9;
Label label;
label = new Label(container, SWT.NONE);
label.setText("Button Type");
label = new Label(container, SWT.NONE);
label.setText("NONE");
label = new Label(container, SWT.NONE);
label.setText("BORDER");
label = new Label(container, SWT.NONE);
label.setText("FLAT");
createLabel(container, SWT.NONE, "Push");
createButton(container, SWT.PUSH, "button1");
createButton(container, SWT.BORDER, "button2");
createButton(container, SWT.FLAT, "button3");
createLabel(container, SWT.NONE, "Radio");
createButton(container, SWT.RADIO, "button1");
createButton(container, SWT.RADIO | SWT.BORDER, "button2");
createButton(container, SWT.RADIO | SWT.FLAT, "button3");
createLabel(container, SWT.NONE, "Toggle");
createButton(container, SWT.TOGGLE, "button1");
createButton(container, SWT.TOGGLE | SWT.BORDER, "button2");
createButton(container, SWT.TOGGLE | SWT.FLAT, "button3");
createLabel(container, SWT.NONE, "Check");
createButton(container, SWT.CHECK, "button1");
createButton(container, SWT.CHECK | SWT.BORDER, "button2");
createButton(container, SWT.CHECK | SWT.FLAT, "button3");
createLabel(container, SWT.NONE, "Arrow | Left");
createButton(container, SWT.ARROW | SWT.LEFT, "button1");
createButton(container, SWT.ARROW | SWT.LEFT | SWT.BORDER, "button2");
createButton(container, SWT.ARROW | SWT.LEFT | SWT.FLAT, "button3");
return container;
}
public void createButton(Composite c, int style, String text) {
Button b = new Button(c, style);
b.setText(text);
}
public void createLabel(Composite c, int style, String text) {
Label l = new Label(c, style);
l.setText(text);
}
}
SWT.CR
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.TreeEditor;
import org.eclipse.swt.events.FocusAdapter;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
public class MainClass {
public static void main(String[] a) {
final Display d = new Display();
final Shell shell = new Shell(d);
shell.setSize(250, 200);
shell.setLayout(new FillLayout());
Text text = new Text(shell, SWT.BORDER);
text.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent event) {
switch (event.keyCode) {
case SWT.CR:
System.out.println(SWT.CR);
case SWT.ESC:
System.out.println(SWT.ESC);
break;
}
}
});
shell.open();
while (!shell.isDisposed()) {
if (!d.readAndDispatch())
d.sleep();
}
d.dispose();
}
}
SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
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.setSize(500,500);
s.open();
DialogExample cs = new DialogExample(s);
cs.open();
}
}
class DialogExample extends Dialog {
DialogExample(Shell parent)
{
super(parent);
}
public String open()
{
Shell parent = getParent();
Shell dialog = new Shell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
dialog.setSize(100,100);
dialog.setText("A Dialog");
dialog.open();
Display display = parent.getDisplay();
while (!dialog.isDisposed())
{ if (!display.readAndDispatch()) display.sleep();
}
return "After Dialog";
}
}
SWT.ESC
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.TreeEditor;
import org.eclipse.swt.events.FocusAdapter;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
public class MainClass {
public static void main(String[] a) {
final Display d = new Display();
final Shell shell = new Shell(d);
shell.setSize(250, 200);
shell.setLayout(new FillLayout());
Text text = new Text(shell, SWT.BORDER);
text.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent event) {
switch (event.keyCode) {
case SWT.CR:
System.out.println(SWT.CR);
case SWT.ESC:
System.out.println(SWT.ESC);
break;
}
}
});
shell.open();
while (!shell.isDisposed()) {
if (!d.readAndDispatch())
d.sleep();
}
d.dispose();
}
}
SWT.NO
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
public class MainClass {
public static void main(String[] a) {
Shell s = new Shell();
MessageBox messageBox = new MessageBox(s, SWT.ICON_QUESTION | SWT.YES | SWT.NO);
messageBox.setMessage("Do you really want to exit?");
messageBox.setText("Exiting Application");
int response = messageBox.open();
if (response == SWT.YES)
System.out.println(SWT.YES);
else if(response == SWT.NO)
System.out.println(SWT.NO);
}
}
SWT.RADIO
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
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.Label;
public class MainClass extends ApplicationWindow {
public MainClass() {
super(null);
}
public static void main(String[] args) {
ApplicationWindow w = new MainClass();
w.setBlockOnOpen(true);
w.open();
Display.getCurrent().dispose();
}
protected Control createContents(Composite parent) {
Composite container = new Composite(parent, SWT.NULL);
this.getShell().setText("ButtonTest");
GridLayout layout = new GridLayout();
container.setLayout(layout);
layout.numColumns = 4;
layout.verticalSpacing = 9;
Label label;
label = new Label(container, SWT.NONE);
label.setText("Button Type");
label = new Label(container, SWT.NONE);
label.setText("NONE");
label = new Label(container, SWT.NONE);
label.setText("BORDER");
label = new Label(container, SWT.NONE);
label.setText("FLAT");
createLabel(container, SWT.NONE, "Push");
createButton(container, SWT.PUSH, "button1");
createButton(container, SWT.BORDER, "button2");
createButton(container, SWT.FLAT, "button3");
createLabel(container, SWT.NONE, "Radio");
createButton(container, SWT.RADIO, "button1");
createButton(container, SWT.RADIO | SWT.BORDER, "button2");
createButton(container, SWT.RADIO | SWT.FLAT, "button3");
createLabel(container, SWT.NONE, "Toggle");
createButton(container, SWT.TOGGLE, "button1");
createButton(container, SWT.TOGGLE | SWT.BORDER, "button2");
createButton(container, SWT.TOGGLE | SWT.FLAT, "button3");
createLabel(container, SWT.NONE, "Check");
createButton(container, SWT.CHECK, "button1");
createButton(container, SWT.CHECK | SWT.BORDER, "button2");
createButton(container, SWT.CHECK | SWT.FLAT, "button3");
createLabel(container, SWT.NONE, "Arrow | Left");
createButton(container, SWT.ARROW | SWT.LEFT, "button1");
createButton(container, SWT.ARROW | SWT.LEFT | SWT.BORDER, "button2");
createButton(container, SWT.ARROW | SWT.LEFT | SWT.FLAT, "button3");
return container;
}
public void createButton(Composite c, int style, String text) {
Button b = new Button(c, style);
b.setText(text);
}
public void createLabel(Composite c, int style, String text) {
Label l = new Label(c, style);
l.setText(text);
}
}
SWT.RADIO | SWT.BORDER
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
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.Label;
public class MainClass extends ApplicationWindow {
public MainClass() {
super(null);
}
public static void main(String[] args) {
ApplicationWindow w = new MainClass();
w.setBlockOnOpen(true);
w.open();
Display.getCurrent().dispose();
}
protected Control createContents(Composite parent) {
Composite container = new Composite(parent, SWT.NULL);
this.getShell().setText("ButtonTest");
GridLayout layout = new GridLayout();
container.setLayout(layout);
layout.numColumns = 4;
layout.verticalSpacing = 9;
Label label;
label = new Label(container, SWT.NONE);
label.setText("Button Type");
label = new Label(container, SWT.NONE);
label.setText("NONE");
label = new Label(container, SWT.NONE);
label.setText("BORDER");
label = new Label(container, SWT.NONE);
label.setText("FLAT");
createLabel(container, SWT.NONE, "Push");
createButton(container, SWT.PUSH, "button1");
createButton(container, SWT.BORDER, "button2");
createButton(container, SWT.FLAT, "button3");
createLabel(container, SWT.NONE, "Radio");
createButton(container, SWT.RADIO, "button1");
createButton(container, SWT.RADIO | SWT.BORDER, "button2");
createButton(container, SWT.RADIO | SWT.FLAT, "button3");
createLabel(container, SWT.NONE, "Toggle");
createButton(container, SWT.TOGGLE, "button1");
createButton(container, SWT.TOGGLE | SWT.BORDER, "button2");
createButton(container, SWT.TOGGLE | SWT.FLAT, "button3");
createLabel(container, SWT.NONE, "Check");
createButton(container, SWT.CHECK, "button1");
createButton(container, SWT.CHECK | SWT.BORDER, "button2");
createButton(container, SWT.CHECK | SWT.FLAT, "button3");
createLabel(container, SWT.NONE, "Arrow | Left");
createButton(container, SWT.ARROW | SWT.LEFT, "button1");
createButton(container, SWT.ARROW | SWT.LEFT | SWT.BORDER, "button2");
createButton(container, SWT.ARROW | SWT.LEFT | SWT.FLAT, "button3");
return container;
}
public void createButton(Composite c, int style, String text) {
Button b = new Button(c, style);
b.setText(text);
}
public void createLabel(Composite c, int style, String text) {
Label l = new Label(c, style);
l.setText(text);
}
}
SWT.SHADOW_ETCHED_IN
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";
}
}
SWT.TOGGLE | SWT.BORDER
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
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.Label;
public class MainClass extends ApplicationWindow {
public MainClass() {
super(null);
}
public static void main(String[] args) {
ApplicationWindow w = new MainClass();
w.setBlockOnOpen(true);
w.open();
Display.getCurrent().dispose();
}
protected Control createContents(Composite parent) {
Composite container = new Composite(parent, SWT.NULL);
this.getShell().setText("ButtonTest");
GridLayout layout = new GridLayout();
container.setLayout(layout);
layout.numColumns = 4;
layout.verticalSpacing = 9;
Label label;
label = new Label(container, SWT.NONE);
label.setText("Button Type");
label = new Label(container, SWT.NONE);
label.setText("NONE");
label = new Label(container, SWT.NONE);
label.setText("BORDER");
label = new Label(container, SWT.NONE);
label.setText("FLAT");
createLabel(container, SWT.NONE, "Push");
createButton(container, SWT.PUSH, "button1");
createButton(container, SWT.BORDER, "button2");
createButton(container, SWT.FLAT, "button3");
createLabel(container, SWT.NONE, "Radio");
createButton(container, SWT.RADIO, "button1");
createButton(container, SWT.RADIO | SWT.BORDER, "button2");
createButton(container, SWT.RADIO | SWT.FLAT, "button3");
createLabel(container, SWT.NONE, "Toggle");
createButton(container, SWT.TOGGLE, "button1");
createButton(container, SWT.TOGGLE | SWT.BORDER, "button2");
createButton(container, SWT.TOGGLE | SWT.FLAT, "button3");
createLabel(container, SWT.NONE, "Check");
createButton(container, SWT.CHECK, "button1");
createButton(container, SWT.CHECK | SWT.BORDER, "button2");
createButton(container, SWT.CHECK | SWT.FLAT, "button3");
createLabel(container, SWT.NONE, "Arrow | Left");
createButton(container, SWT.ARROW | SWT.LEFT, "button1");
createButton(container, SWT.ARROW | SWT.LEFT | SWT.BORDER, "button2");
createButton(container, SWT.ARROW | SWT.LEFT | SWT.FLAT, "button3");
return container;
}
public void createButton(Composite c, int style, String text) {
Button b = new Button(c, style);
b.setText(text);
}
public void createLabel(Composite c, int style, String text) {
Label l = new Label(c, style);
l.setText(text);
}
}
SWT.TOGGLE | SWT.FLAT
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
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.Label;
public class MainClass extends ApplicationWindow {
public MainClass() {
super(null);
}
public static void main(String[] args) {
ApplicationWindow w = new MainClass();
w.setBlockOnOpen(true);
w.open();
Display.getCurrent().dispose();
}
protected Control createContents(Composite parent) {
Composite container = new Composite(parent, SWT.NULL);
this.getShell().setText("ButtonTest");
GridLayout layout = new GridLayout();
container.setLayout(layout);
layout.numColumns = 4;
layout.verticalSpacing = 9;
Label label;
label = new Label(container, SWT.NONE);
label.setText("Button Type");
label = new Label(container, SWT.NONE);
label.setText("NONE");
label = new Label(container, SWT.NONE);
label.setText("BORDER");
label = new Label(container, SWT.NONE);
label.setText("FLAT");
createLabel(container, SWT.NONE, "Push");
createButton(container, SWT.PUSH, "button1");
createButton(container, SWT.BORDER, "button2");
createButton(container, SWT.FLAT, "button3");
createLabel(container, SWT.NONE, "Radio");
createButton(container, SWT.RADIO, "button1");
createButton(container, SWT.RADIO | SWT.BORDER, "button2");
createButton(container, SWT.RADIO | SWT.FLAT, "button3");
createLabel(container, SWT.NONE, "Toggle");
createButton(container, SWT.TOGGLE, "button1");
createButton(container, SWT.TOGGLE | SWT.BORDER, "button2");
createButton(container, SWT.TOGGLE | SWT.FLAT, "button3");
createLabel(container, SWT.NONE, "Check");
createButton(container, SWT.CHECK, "button1");
createButton(container, SWT.CHECK | SWT.BORDER, "button2");
createButton(container, SWT.CHECK | SWT.FLAT, "button3");
createLabel(container, SWT.NONE, "Arrow | Left");
createButton(container, SWT.ARROW | SWT.LEFT, "button1");
createButton(container, SWT.ARROW | SWT.LEFT | SWT.BORDER, "button2");
createButton(container, SWT.ARROW | SWT.LEFT | SWT.FLAT, "button3");
return container;
}
public void createButton(Composite c, int style, String text) {
Button b = new Button(c, style);
b.setText(text);
}
public void createLabel(Composite c, int style, String text) {
Label l = new Label(c, style);
l.setText(text);
}
}
SWT.YES
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
public class MainClass {
public static void main(String[] a) {
Shell s = new Shell();
MessageBox messageBox = new MessageBox(s, SWT.ICON_QUESTION | SWT.YES | SWT.NO);
messageBox.setMessage("Do you really want to exit?");
messageBox.setText("Exiting Application");
int response = messageBox.open();
if (response == SWT.YES)
System.out.println(SWT.YES);
else if(response == SWT.NO)
System.out.println(SWT.NO);
}
}