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:ComboRemoveMultipleItems.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", "E", "F" };

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

    combo.remove(2, 4);

    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:StyleRangeStyledTextSet.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");

    // Use the empty constructor and set the fields
    StyleRange sr1 = new StyleRange();
    sr1.start = 7;//from www  . jav a 2  s  .c  o  m
    sr1.length = 14;
    sr1.foreground = display.getSystemColor(SWT.COLOR_GREEN);
    sr1.background = display.getSystemColor(SWT.COLOR_WHITE);
    sr1.fontStyle = SWT.BOLD;

    styledText.setStyleRange(sr1);

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

From source file:FocusEventInOut.java

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

    Text t = new Text(shell, SWT.SINGLE | SWT.BORDER);
    t.setBounds(10, 85, 100, 32);/*from   w w  w .j  a  va  2  s.  c o  m*/

    Text t2 = new Text(shell, SWT.SINGLE | SWT.BORDER);
    t2.setBounds(10, 25, 100, 32);

    t2.addListener(SWT.FocusIn, new Listener() {
        public void handleEvent(Event e) {
            System.out.println("focus in");
        }
    });
    t2.addListener(SWT.FocusOut, new Listener() {
        public void handleEvent(Event e) {
            System.out.println("focus out");
        }
    });

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

    s.setText("A Shell Menu Example");

    Menu m = new Menu(s, SWT.BAR);

    // create a file menu and add an exit item
    final MenuItem file = new MenuItem(m, SWT.CASCADE);
    file.setText("File");
    final Menu filemenu = new Menu(s, SWT.DROP_DOWN);
    file.setMenu(filemenu);//from w  w  w.  j ava2 s. co m
    final MenuItem openItem = new MenuItem(filemenu, SWT.PUSH);
    openItem.setText("Open");
    final MenuItem separator = new MenuItem(filemenu, SWT.SEPARATOR);
    final MenuItem exitItem = new MenuItem(filemenu, SWT.PUSH);
    exitItem.setText("Exit");

    s.setMenuBar(m);

    s.open();
    while (!s.isDisposed()) {
        if (!d.readAndDispatch())
            d.sleep();
    }
    d.dispose();

}

From source file:PopupMenuMenuEvent.java

public static void main(String[] args) {
    Display display = new Display();
    final Clipboard cb = new Clipboard(display);
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    final Text text = new Text(shell, SWT.BORDER | SWT.MULTI | SWT.WRAP);
    Menu menu = new Menu(shell, SWT.POP_UP);
    final MenuItem copyItem = new MenuItem(menu, SWT.PUSH);

    copyItem.setText("Copy");

    menu.addMenuListener(new MenuAdapter() {
        public void menuShown(MenuEvent e) {
            System.out.println("Menu event");
        }/*from   w  w  w .ja  va  2  s.c  o  m*/
    });

    text.setMenu(menu);

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

From source file:Snippet113.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    Table table = new Table(shell, SWT.CHECK | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    for (int i = 0; i < 12; i++) {
        TableItem item = new TableItem(table, SWT.NONE);
        item.setText("Item " + i);
    }//  w w w . j a v a 2s. com
    table.setSize(100, 100);
    table.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            String string = event.detail == SWT.CHECK ? "Checked" : "Selected";
            System.out.println(event.item + " " + string);
        }
    });
    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) {

    final Display d = new Display();
    final Shell shell = new Shell(d);

    shell.setSize(250, 200);/*  www.  ja  v  a  2  s . c om*/

    final String RUN = "Press to Run";
    final String IS_RUNNING = "Running...";

    shell.setLayout(new FillLayout());
    final Button button = new Button(shell, SWT.PUSH);
    button.setText(RUN);
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            button.setText(IS_RUNNING);

            BusyIndicator.showWhile(button.getDisplay(), new SleepThread(1000));

            button.setText(RUN);
        }
    });

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

}

From source file:ShellEscapeClose.java

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    shell.addListener(SWT.Traverse, new Listener() {
        public void handleEvent(Event event) {
            switch (event.detail) {
            case SWT.TRAVERSE_ESCAPE:
                shell.close();// w  w w  .  j a v a  2 s  .  com
                event.detail = SWT.TRAVERSE_NONE;
                event.doit = false;
                break;
            }
        }
    });
    Button button = new Button(shell, SWT.PUSH);
    button.setText("A Button (that doesn't process Escape)");
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:ComboFindingItem.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  2 s.c om*/

    System.out.println(combo.indexOf("B"));

    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:BrowserExample.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    shell.setText("Browser example");
    BrowserExample instance = new BrowserExample(shell);
    Image icon = new Image(display, "java2s.gif");
    shell.setImage(icon);//from ww  w  .jav  a  2  s .co m
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    icon.dispose();
    instance.dispose();
    display.dispose();
}