List of usage examples for org.eclipse.swt.widgets Button getGrayed
public boolean getGrayed()
true
if the receiver is grayed, and false otherwise. 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 ww w .j a v a 2 s . c o m 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(); }