В SWT виджет кнопки состоит из пяти кнопок стиля.
1) Нормальная кнопка — SWT.PUSH
2) Кнопка со стрелкой — стрелка
3) Кнопка переключения — SWT.TOGGLE
4) Кнопка флажка — SWT.CHECK
5) Радио кнопка — SWT.RADIO

Здесь я демонстрирую, как создать эти кнопки в SWT
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
открытый класс SWTButton {
public static void main (String [] args) {
Дисплей дисплей = новый дисплей ();
Shell shell = новая оболочка (дисплей);
//нажать кнопку
Кнопка pushButton = новая кнопка (оболочка, SWT.PUSH);
pushButton.setLocation (50, 50);
pushButton.setText («Я - кнопка»);
pushButton.pack ();
// кнопка со стрелкой
Button arrowLeftButton = new Button (shell, SWT.ARROW | SWT.LEFT);
arrowLeftButton.setLocation (50, 100);
arrowLeftButton.setText ( ЛЕВЫЙ);
arrowLeftButton.pack ();
Button arrowRightButton = new Button (shell, SWT.ARROW | SWT.RIGHT);
arrowRightButton.setLocation (80, 100);
arrowRightButton.setText ( ПРАВАЯ);
arrowRightButton.pack ();
Button arrowUpButton = new Button (shell, SWT.ARROW | SWT.UP);
arrowUpButton.setLocation (110, 100);
arrowUpButton.setText ( UP);
arrowUpButton.pack ();
Button arrowDownButton = new Button (shell, SWT.ARROW | SWT.DOWN);
arrowDownButton.setLocation (140, 100);
arrowDownButton.setText ( DOWN);
arrowDownButton.pack ();
// тумблер
Button toggleNotPressedButton = new Button (shell, SWT.TOGGLE);
toggleNotPressedButton.setSelection (ложь);
toggleNotPressedButton.setLocation (50, 150);
toggleNotPressedButton.setText («Кнопка не нажата»);
toggleNotPressedButton.pack ();
Button togglePressedButton = new Button (shell, SWT.TOGGLE);
togglePressedButton.setSelection (истина);
togglePressedButton.setLocation (170, 150);
togglePressedButton.setText (Кнопка нажата);
togglePressedButton.pack ();
// флажок
Button [] checkBoxs = new Button [3];
checkBoxs [0] = новая кнопка (shell, SWT.CHECK);
checkBoxs [0] .setSelection (истина);
checkBoxs [0] .setText («Выбор 1»);
checkBoxs [0] .setLocation (50200);
checkBoxs [0] .pack ();
checkBoxs [1] = новая кнопка (shell, SWT.CHECK);
checkBoxs [1] .setText («Выбор 2»);
checkBoxs [1] .setLocation (120200);
checkBoxs [1] .pack ();
checkBoxs [2] = новая кнопка (shell, SWT.CHECK);
checkBoxs [2] .setText («Выбор 3»);
checkBoxs [2] .setLocation (190200);
checkBoxs [2] .pack ();
//радио
Кнопка [] radioButtons = новая кнопка [3];
radioButtons [0] = новая кнопка (оболочка, SWT.RADIO);
Radiobuttons [0] .setSelection (истина);
radioButtons [0] .setText («Выбор 1»);
Radiobuttons [0] .setLocation (50250);
Radiobuttons [0] .pack ();
radioButtons [1] = новая кнопка (оболочка, SWT.RADIO);
radioButtons [1] .setText («Выбор 2»);
Radiobuttons [1] .setLocation (120250);
Radiobuttons [1] .pack ();
radioButtons [2] = новая кнопка (оболочка, SWT.RADIO);
radioButtons [2] .setText («Выбор 3»);
Radiobuttons [2] .setLocation (190250);
Radiobuttons [2] .pack ();
shell.setSize (500500);
shell.open ();
while (! shell.isDisposed ()) {
if (! display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
}
0.00 (0%) 0 votes




