List of usage examples for org.eclipse.swt.widgets Button setGrayed
public void setGrayed(boolean grayed)
From source file:org.eclipse.swt.snippets.Snippet293.java
public static void main(java.lang.String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 293"); shell.setLayout(new GridLayout()); Button b1 = new Button(shell, SWT.CHECK); b1.setText("State 1"); b1.setSelection(true);//w ww . j a v a2s .c om Button b2 = new Button(shell, SWT.CHECK); b2.setText("State 2"); b2.setSelection(false); Button b3 = new Button(shell, SWT.CHECK); b3.setText("State 3"); b3.setSelection(true); b3.setGrayed(true); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet315.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 315"); shell.setLayout(new GridLayout()); final Button button = new Button(shell, SWT.CHECK); button.setLayoutData(//from w w w.ja v a 2s. c om new GridData(GridData.GRAB_VERTICAL | GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_CENTER)); button.setText("Tri-state"); /* Make the button toggle between three states */ button.addListener(SWT.Selection, e -> { if (button.getSelection()) { if (!button.getGrayed()) { button.setGrayed(true); } } else { if (button.getGrayed()) { button.setGrayed(false); button.setSelection(true); } } }); /* Read the tri-state button (application code) */ button.addListener(SWT.Selection, e -> { if (button.getGrayed()) { System.out.println("Grayed"); } else { if (button.getSelection()) { System.out.println("Selected"); } else { System.out.println("Not selected"); } } }); shell.setSize(300, 300); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }