Example usage for org.eclipse.swt.widgets Button getGrayed

List of usage examples for org.eclipse.swt.widgets Button getGrayed

Introduction

In this page you can find the example usage for org.eclipse.swt.widgets Button getGrayed.

Prototype

public boolean getGrayed() 

Source Link

Document

Returns true if the receiver is grayed, and false otherwise.

Usage

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();
}