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

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

Introduction

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

Prototype

public void dispose() 

Source Link

Usage

From source file:EventSelection.java

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display, SWT.SHELL_TRIM);
    shell.setLayout(new FillLayout());

    Button button = new Button(shell, SWT.RIGHT);

    button.setText("text on the button");

    button.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent arg0) {
            System.out.println("selected");
        }/*  w w w .  j  ava  2 s  .  c o m*/

        public void widgetDefaultSelected(SelectionEvent arg0) {
        }
    });

    shell.open();
    // Set up the event loop.
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            // If no more entries in event queue
            display.sleep();
        }
    }
    display.dispose();
}

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

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 183");
    Link link = new Link(shell, SWT.NONE);
    String text = "The SWT component is designed to provide <a>efficient</a>, <a>portable</a> <a href=\"native\">access to the user-interface facilities of the operating systems</a> on which it is implemented.";
    link.setText(text);//from  ww  w . j  a  v a 2  s  .  c  o m
    Rectangle clientArea = shell.getClientArea();
    link.setBounds(clientArea.x, clientArea.y, 400, 400);
    link.addListener(SWT.Selection, event -> System.out.println("Selection: " + event.text));
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

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

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 11");
    Text text = new Text(shell, SWT.BORDER | SWT.V_SCROLL);
    Rectangle clientArea = shell.getClientArea();
    text.setBounds(clientArea.x + 10, clientArea.y + 10, 100, 100);
    for (int i = 0; i < 16; i++) {
        text.append("Line " + i + "\n");
    }//from  ww  w  .j  ava  2s  .  c om
    shell.open();
    text.setSelection(30);
    System.out.println("selection=" + text.getSelection());
    System.out.println("caret position=" + text.getCaretPosition());
    System.out.println("caret location=" + text.getCaretLocation());
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:ToolBarWrapResize.java

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    final ToolBar toolBar = new ToolBar(shell, SWT.WRAP);
    for (int i = 0; i < 12; i++) {
        ToolItem item = new ToolItem(toolBar, SWT.PUSH);
        item.setText("Item " + i);
    }/*  w  ww.j a  va2s  . c  o m*/
    shell.addListener(SWT.Resize, new Listener() {
        public void handleEvent(Event e) {
            Rectangle rect = shell.getClientArea();
            Point size = toolBar.computeSize(rect.width, SWT.DEFAULT);
            toolBar.setSize(size);
        }
    });
    toolBar.pack();
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:ComboRemoveItems.java

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

    String[] ITEMS = { "A", "B", "C", "D" };

    final Combo combo = new Combo(shell, SWT.DROP_DOWN);
    combo.setItems(ITEMS);//from   w  w w.j a  v  a2s.  c o m

    combo.remove(0);

    combo.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            System.out.println(combo.getText());
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            System.out.println(combo.getText());
        }
    });

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

From source file:ComboSelect.java

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

    String[] ITEMS = { "A", "B", "C", "D" };

    final Combo combo = new Combo(shell, SWT.DROP_DOWN);
    combo.setItems(ITEMS);// w  w  w  .java  2  s  .  c o  m

    combo.select(2);

    combo.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            System.out.println(combo.getText());
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            System.out.println(combo.getText());
        }
    });

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

From source file:ComboAddItem.java

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

    String[] ITEMS = { "A", "B", "C", "D" };

    final Combo combo = new Combo(shell, SWT.DROP_DOWN);
    combo.setItems(ITEMS);//  w  ww .j  a  v a 2s. c  o m

    combo.add("new");

    combo.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            System.out.println(combo.getText());
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            System.out.println(combo.getText());
        }
    });

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

From source file:ComboDeselect.java

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

    String[] ITEMS = { "A", "B", "C", "D" };

    final Combo combo = new Combo(shell, SWT.DROP_DOWN);
    combo.setItems(ITEMS);//from   w w  w  . j  a  v  a 2s  . c om

    combo.deselect(0);

    combo.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            System.out.println(combo.getText());
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            System.out.println(combo.getText());
        }
    });

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

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

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Snippet 76");
    final TabFolder tabFolder = new TabFolder(shell, SWT.BORDER);
    Rectangle clientArea = shell.getClientArea();
    tabFolder.setLocation(clientArea.x, clientArea.y);
    for (int i = 0; i < 6; i++) {
        TabItem item = new TabItem(tabFolder, SWT.NONE);
        item.setText("TabItem " + i);
        Button button = new Button(tabFolder, SWT.PUSH);
        button.setText("Page " + i);
        item.setControl(button);/* w w w .  j a  v a2s . c o m*/
    }
    tabFolder.pack();
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:ComboAddingItem.java

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

    String[] ITEMS = { "A", "B", "C", "D" };

    final Combo combo = new Combo(shell, SWT.DROP_DOWN);
    combo.setItems(ITEMS);/*from ww  w  . j  ava 2 s. c o m*/

    combo.add("new", 2);

    combo.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            System.out.println(combo.getText());
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            System.out.println(combo.getText());
        }
    });

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