Example usage for org.eclipse.swt.widgets Display Display

List of usage examples for org.eclipse.swt.widgets Display Display

Introduction

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

Prototype

public Display() 

Source Link

Document

Constructs a new instance of this class.

Usage

From source file:SpinnerFloatPoint.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Spinner with float values");
    shell.setLayout(new GridLayout());
    final Spinner spinner = new Spinner(shell, SWT.NONE);
    // allow 3 decimal places
    spinner.setDigits(3);/*from   w w w.jav a2  s  . c om*/
    // set the minimum value to 0.001
    spinner.setMinimum(1);
    // set the maximum value to 20
    spinner.setMaximum(20000);
    // set the increment value to 0.010
    spinner.setIncrement(10);
    // set the seletion to 3.456
    spinner.setSelection(3456);
    shell.setSize(200, 200);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:MainClass.java

public static void main(String[] a) {
    Display d = new Display();
    Shell s = new Shell(d);

    final ToolBar bar = new ToolBar(s, SWT.HORIZONTAL);
    bar.setSize(300, 70);/* w  w w  .  j ava2  s  .c o  m*/
    bar.setLocation(0, 0);

    // create images for toolbar buttons
    // final Image saveIcon = new Image(d, "c:\\icons\\save.jpg");
    // final Image openIcon = new Image(d, "c:\\icons\\open.jpg");
    // final Image cutIcon = new Image(d, "c:\\icons\\cut.jpg");
    // final Image copyIcon = new Image(d, "c:\\icons\\copy.jpg");
    // final Image pasteIcon = new Image(d, "c:\\icons\\paste.jpg");

    // create and add the button for performing an open operation
    final ToolItem openToolItem = new ToolItem(bar, SWT.PUSH);
    // openToolItem.setImage(openIcon);
    openToolItem.setText("Open");
    openToolItem.setToolTipText("Open File");

    // create and add the button for performing a save operation
    final ToolItem saveToolItem = new ToolItem(bar, SWT.PUSH);
    // saveToolItem.setImage(saveIcon);
    saveToolItem.setText("Save");
    saveToolItem.setToolTipText("Save File");
    s.open();
    while (!s.isDisposed()) {
        if (!d.readAndDispatch())
            d.sleep();
    }
    d.dispose();
}

From source file:MessageBoxWarningBoxYESNOCancelButton.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);

    int style = SWT.ICON_WARNING | SWT.YES | SWT.NO | SWT.CANCEL;

    MessageBox messageBox = new MessageBox(shell, style);
    messageBox.setMessage("Message");
    int rc = messageBox.open();

    switch (rc) {
    case SWT.OK://  www.  j  a  v a  2  s.  co  m
        System.out.println("SWT.OK");
        break;
    case SWT.CANCEL:
        System.out.println("SWT.CANCEL");
        break;
    case SWT.YES:
        System.out.println("SWT.YES");
        break;
    case SWT.NO:
        System.out.println("SWT.NO");
        break;
    case SWT.RETRY:
        System.out.println("SWT.RETRY");
        break;
    case SWT.ABORT:
        System.out.println("SWT.ABORT");
        break;
    case SWT.IGNORE:
        System.out.println("SWT.IGNORE");
        break;
    }

    display.dispose();
}

From source file:StyledTextClearKeyBinding.java

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);

    StyledText styledText = new StyledText(shell, SWT.V_SCROLL | SWT.BORDER);
    styledText.setText("12345");

    styledText.setKeyBinding('i' | SWT.ALT, ST.TOGGLE_OVERWRITE);

    //clear/* w ww  .j  a v  a  2s  . com*/
    styledText.setKeyBinding('i' | SWT.ALT, SWT.NULL);

    styledText.setBounds(10, 10, 100, 100);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();

}

From source file:DrawOval.java

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent event) {
            Rectangle rect = shell.getClientArea();
            event.gc.drawOval(0, 0, rect.width - 1, rect.height - 1);
        }/*from  w w  w  .j a v a2s . com*/
    });
    shell.setBounds(10, 10, 200, 200);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:StyleRangeSetArray.java

License:asdf

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);

    final StyledText styledText = new StyledText(shell, SWT.V_SCROLL | SWT.BORDER);
    styledText.setText("asdfasdfasdfasdf12345678910234567890");

    StyleRange[] ranges = new StyleRange[2];
    ranges[0] = new StyleRange(0, 3, display.getSystemColor(SWT.COLOR_GREEN), null);
    ranges[1] = new StyleRange(3, 6, display.getSystemColor(SWT.COLOR_BLUE), null);

    styledText.setStyleRanges(ranges);/*from   w ww. j  a v a  2 s . com*/

    styledText.setBounds(10, 10, 500, 100);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}

From source file:DisplayFilterEvent.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Left click your mouse");
    shell.setSize(200, 100);// w  ww . j  a va2  s.c o m
    shell.open();

    shell.addListener(SWT.MouseDown, new SimpleListener("Shell mouse down listener"));

    display.addFilter(SWT.MouseDown, new SimpleListener("Display mouse down Listener"));

    display.addFilter(SWT.MouseUp, new SimpleListener("Display mouse up Listener"));

    shell.open();
    while (!shell.isDisposed()) { // Event loop.
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:MessageBoxInformationIconOKCancelButton.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);

    int style = SWT.ICON_INFORMATION | SWT.OK | SWT.CANCEL;

    MessageBox messageBox = new MessageBox(shell, style);
    messageBox.setMessage("Message");
    int rc = messageBox.open();

    switch (rc) {
    case SWT.OK:/*  w w  w.ja  va2s.  c o  m*/
        System.out.println("SWT.OK");
        break;
    case SWT.CANCEL:
        System.out.println("SWT.CANCEL");
        break;
    case SWT.YES:
        System.out.println("SWT.YES");
        break;
    case SWT.NO:
        System.out.println("SWT.NO");
        break;
    case SWT.RETRY:
        System.out.println("SWT.RETRY");
        break;
    case SWT.ABORT:
        System.out.println("SWT.ABORT");
        break;
    case SWT.IGNORE:
        System.out.println("SWT.IGNORE");
        break;
    }

    display.dispose();
}

From source file:FontSelectionDialogDisplay.java

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);

    FontDialog dlg = new FontDialog(shell);
    FontData fontData = dlg.open();/*from  w ww  .j  ava 2s  .co  m*/
    if (fontData != null) {
        Font font = new Font(shell.getDisplay(), fontData);

        font.dispose();
    }

    display.dispose();

}

From source file:WidgetSizeCompute.java

public static void main(String[] args) {
    final Display display = new Display();
    Shell shell = new Shell(display);

    shell.setLayout(new GridLayout());

    Button button = new Button(shell, SWT.PUSH | SWT.LEFT);
    button.setText("Button");

    System.out.println("Bounds: " + button.getBounds());
    System.out.println("computeSize: " + button.computeSize(100, SWT.DEFAULT));
    System.out.println("computeSize: " + button.computeSize(40, SWT.DEFAULT));
    System.out.println("computeSize: " + button.computeSize(SWT.DEFAULT, 100));
    System.out.println("computeSize: " + button.computeSize(SWT.DEFAULT, 20));
    System.out.println("computeSize: " + button.computeSize(SWT.DEFAULT, 15));
    System.out.println("computeSize: " + button.computeSize(100, 200));
    System.out.println("computeSize: " + button.computeSize(SWT.DEFAULT, SWT.DEFAULT));

    shell.open();//w  w w  .j a v a2 s  . c  o  m
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
}