Example usage for org.eclipse.swt.widgets Label getBackground

List of usage examples for org.eclipse.swt.widgets Label getBackground

Introduction

In this page you can find the example usage for org.eclipse.swt.widgets Label getBackground.

Prototype

public Color getBackground() 

Source Link

Document

Returns the receiver's background color.

Usage

From source file:TimeStopWhenButtonPressing.java

public static void main(String[] args) {
    final Display display = new Display();
    final Color red = display.getSystemColor(SWT.COLOR_RED);
    final Color blue = display.getSystemColor(SWT.COLOR_BLUE);
    Shell shell = new Shell(display);
    shell.setLayout(new RowLayout());
    Button button = new Button(shell, SWT.PUSH);
    button.setText("Stop Timer");
    final Label label = new Label(shell, SWT.BORDER);
    label.setBackground(red);//from  w ww.  j  a v  a  2 s  .co  m
    final int time = 500;
    final Runnable timer = new Runnable() {
        public void run() {
            if (label.isDisposed())
                return;
            Color color = label.getBackground().equals(red) ? blue : red;
            label.setBackground(color);
            display.timerExec(time, this);
        }
    };
    display.timerExec(time, timer);
    button.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            display.timerExec(-1, timer);
        }
    });
    button.pack();
    label.setLayoutData(new RowData(button.getSize()));
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:org.eclipse.swt.snippets.Snippet68.java

public static void main(String[] args) {
    final Display display = new Display();
    final Color red = display.getSystemColor(SWT.COLOR_RED);
    final Color blue = display.getSystemColor(SWT.COLOR_BLUE);
    Shell shell = new Shell(display);
    shell.setText("Snippet 68");
    shell.setLayout(new RowLayout());
    Button button = new Button(shell, SWT.PUSH);
    button.setText("Stop Timer");
    final Label label = new Label(shell, SWT.BORDER);
    label.setBackground(red);/*from   w  w w.j  a  va  2 s  .co m*/
    final int time = 500;
    final Runnable timer = new Runnable() {
        @Override
        public void run() {
            if (label.isDisposed())
                return;
            Color color = label.getBackground().equals(red) ? blue : red;
            label.setBackground(color);
            display.timerExec(time, this);
        }
    };
    display.timerExec(time, timer);
    button.addListener(SWT.Selection, event -> display.timerExec(-1, timer));
    button.pack();
    label.setLayoutData(new RowData(button.getSize()));
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:ColorDialogButtonActionSetLabelBackground.java

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Color Chooser");
    shell.setLayout(new GridLayout(2, false));

    final Label colorLabel = new Label(shell, SWT.NONE);
    colorLabel.setText("Color");

    Button button = new Button(shell, SWT.PUSH);
    button.setText("Color...");
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            Color color = new Color(shell.getDisplay(), new RGB(0, 255, 0));
            ColorDialog dlg = new ColorDialog(shell);

            dlg.setRGB(colorLabel.getBackground().getRGB());
            dlg.setText("Choose a Color");

            RGB rgb = dlg.open();//  w  w w .ja va  2s .c  om
            if (rgb != null) {
                color.dispose();
                color = new Color(shell.getDisplay(), rgb);
                colorLabel.setBackground(color);
                color.dispose();
            }
        }
    });

    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }

    display.dispose();

}

From source file:ChooseColor.java

/**
 * Creates the window contents//  w w  w.  j  a  v a  2 s  .c o  m
 * 
 * @param shell the parent shell
 */
private void createContents(final Shell shell) {
    shell.setLayout(new GridLayout(2, false));

    // Start with Celtics green
    color = new Color(shell.getDisplay(), new RGB(0, 255, 0));

    // Use a label full of spaces to show the color
    final Label colorLabel = new Label(shell, SWT.NONE);
    colorLabel.setText("                              ");
    colorLabel.setBackground(color);

    Button button = new Button(shell, SWT.PUSH);
    button.setText("Color...");
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            // Create the color-change dialog
            ColorDialog dlg = new ColorDialog(shell);

            // Set the selected color in the dialog from
            // user's selected color
            dlg.setRGB(colorLabel.getBackground().getRGB());

            // Change the title bar text
            dlg.setText("Choose a Color");

            // Open the dialog and retrieve the selected color
            RGB rgb = dlg.open();
            if (rgb != null) {
                // Dispose the old color, create the
                // new one, and set into the label
                color.dispose();
                color = new Color(shell.getDisplay(), rgb);
                colorLabel.setBackground(color);
            }
        }
    });
}