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

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

    GridLayout gridLayout = new GridLayout();
    gridLayout.marginHeight = 20;//from  w  w w . j  a  va  2s.  co  m
    gridLayout.marginWidth = 30;

    shell.setLayout(gridLayout);

    Button button1 = new Button(shell, SWT.PUSH);
    button1.setText("button1");

    List list = new List(shell, SWT.BORDER);
    list.add("item 1");
    list.add("item 2");
    list.add("item 3");

    Button button2 = new Button(shell, SWT.PUSH);
    button2.setText("button #2");

    Button button3 = new Button(shell, SWT.PUSH);
    button3.setText("button #3");

    shell.setSize(450, 400);
    shell.open();

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

From source file:ListDefaultSelectionListener.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    final List list = new List(shell, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL);

    for (int i = 0; i < 128; i++) {
        list.add("Item " + i);
    }//from   w w  w.  j  ava2 s  . co m
    list.setBounds(0, 0, 100, 100);

    list.addListener(SWT.DefaultSelection, new Listener() {
        public void handleEvent(Event e) {
            String string = "";
            int[] selection = list.getSelectionIndices();
            for (int i = 0; i < selection.length; i++)
                string += selection[i] + " ";
            System.out.println("DefaultSelection={" + string + "}");
        }
    });

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

From source file:SashFromMaximizeControl.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("SashForm Test");
    // Fill the parent window with the buttons and sash
    shell.setLayout(new FillLayout());

    // Create the SashForm and the buttons
    SashForm sashForm = new SashForm(shell, SWT.VERTICAL);
    new Button(sashForm, SWT.PUSH).setText("Left");
    Button control = new Button(sashForm, SWT.PUSH);
    control.setText("Right");
    sashForm.setOrientation(SWT.HORIZONTAL);

    if (control == sashForm.getMaximizedControl()) {
        sashForm.setMaximizedControl(null);
    } else {//from  w  w w  .  j  a  v  a2  s  . co  m
        sashForm.setMaximizedControl(control);
    }

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

}

From source file:TextTraverseListenerTab.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setBounds(10, 10, 200, 200);/*from ww  w . j  a v  a2  s .  c  o  m*/
    Text text1 = new Text(shell, SWT.MULTI | SWT.WRAP);
    text1.setBounds(10, 10, 150, 50);
    text1.setText("Tab will traverse out from here.");
    text1.addTraverseListener(new TraverseListener() {
        public void keyTraversed(TraverseEvent e) {
            if (e.detail == SWT.TRAVERSE_TAB_NEXT || e.detail == SWT.TRAVERSE_TAB_PREVIOUS) {
                e.doit = true;
            }
        }
    });
    Text text2 = new Text(shell, SWT.MULTI | SWT.WRAP);
    text2.setBounds(10, 100, 150, 50);
    text2.setText("But Tab will NOT traverse out from here (Ctrl+Tab will).");
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:MenuAddMenuItem.java

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

    // Create the bar menu
    Menu menuBar = new Menu(shell, SWT.BAR);

    // Create the File item's dropdown menu
    Menu fileMenu = new Menu(menuBar);

    // Create all the items in the bar menu
    MenuItem fileItem = new MenuItem(menuBar, SWT.CASCADE);
    fileItem.setText("File");
    fileItem.setMenu(fileMenu);/*  w w w . ja  va2 s  .c  o m*/

    // Create all the items in the File dropdown menu
    MenuItem newItem = new MenuItem(fileMenu, SWT.NONE);
    newItem.setText("New");
    MenuItem openItem = new MenuItem(fileMenu, SWT.NONE);
    openItem.setText("Open...");
    MenuItem saveItem = new MenuItem(fileMenu, SWT.NONE);
    saveItem.setText("Save");
    MenuItem saveAsItem = new MenuItem(fileMenu, SWT.NONE);
    saveAsItem.setText("Save As...");

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

From source file:GridLayoutSpacing.java

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

    GridLayout gridLayout = new GridLayout();
    gridLayout.horizontalSpacing = 20;//from   w  w w.j  av a  2s  .  c  om
    gridLayout.verticalSpacing = 30;

    shell.setLayout(gridLayout);

    Button button1 = new Button(shell, SWT.PUSH);
    button1.setText("button1");

    List list = new List(shell, SWT.BORDER);
    list.add("item 1");
    list.add("item 2");
    list.add("item 3");

    Button button2 = new Button(shell, SWT.PUSH);
    button2.setText("button #2");

    Button button3 = new Button(shell, SWT.PUSH);
    button3.setText("button #3");

    shell.setSize(450, 400);
    shell.open();

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

From source file:MainClass.java

public static void main(String[] a) {
    Display display = new Display();
    Shell shell = new Shell(display);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;/*from w  ww.  jav a  2  s  . c  om*/
    layout.makeColumnsEqualWidth = true;
    shell.setLayout(layout);

    GridData data = new GridData(GridData.FILL_BOTH);
    Button one = new Button(shell, SWT.PUSH);
    one.setText("one");
    one.setLayoutData(data);

    data = new GridData(GridData.FILL_BOTH);
    Button two = new Button(shell, SWT.PUSH);
    two.setText("two");
    two.setLayoutData(data);

    data = new GridData(GridData.FILL_BOTH);
    Button three = new Button(shell, SWT.PUSH);
    three.setText("three");
    three.setLayoutData(data);

    data = new GridData(GridData.FILL_BOTH);
    Button four = new Button(shell, SWT.PUSH);
    four.setText("four");
    four.setLayoutData(data);

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

From source file:MainClass.java

public static void main(String[] a) {
    final String[] ITEMS = { "A", "B", "C", "D", "E" };

    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new RowLayout());

    // Create a drop-down combo
    Combo combo = new Combo(shell, SWT.DROP_DOWN);
    combo.setItems(ITEMS);/*from w ww .  j  a v  a2s.  co m*/

    // Create a read only combo
    Combo readOnly = new Combo(shell, SWT.DROP_DOWN | SWT.READ_ONLY);
    readOnly.setItems(ITEMS);

    // Create a "simple" combo
    Combo simple = new Combo(shell, SWT.SIMPLE);
    simple.setItems(ITEMS);

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

}

From source file:MenuSeparatorAdd.java

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

    // Create the bar menu
    Menu menuBar = new Menu(shell, SWT.BAR);

    // Create the File item's dropdown menu
    Menu fileMenu = new Menu(menuBar);

    // Create all the items in the bar menu
    MenuItem fileItem = new MenuItem(menuBar, SWT.CASCADE);
    fileItem.setText("File");
    fileItem.setMenu(fileMenu);//w  w w.  j  a  va 2s  .com

    // Create all the items in the File dropdown menu
    MenuItem newItem = new MenuItem(fileMenu, SWT.NONE);
    newItem.setText("New");

    //  Create the first separator
    new MenuItem(fileMenu, SWT.SEPARATOR);

    MenuItem saveItem = new MenuItem(fileMenu, SWT.NONE);
    saveItem.setText("Save");

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

From source file:MainClass.java

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

    s.setSize(250, 250);/*from w  w w.j  a  v a2 s  . c o  m*/
    s.setText("A Combo Example");
    final Combo c1 = new Combo(s, SWT.READ_ONLY);
    c1.setBounds(50, 50, 150, 65);
    final Combo c2 = new Combo(s, SWT.READ_ONLY);
    c2.setBounds(50, 85, 150, 65);
    c2.setEnabled(false);
    String items[] = { "Item One", "Item Two", "Item Three", "Item Four", "Item Five" };
    c1.setItems(items);
    c1.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            if (c1.getText().equals("Item One")) {
                String newItems[] = { "A", "B", "C" };
                c2.setItems(newItems);
                c2.setEnabled(true);
            } else if (c1.getText().equals("Item Two")) {
                String newItems[] = { "A", "B", "C" };
                c2.setItems(newItems);
                c2.setEnabled(true);
            } else {
                c2.add("Not Applicable");
                c2.setText("Not Applicable");
            }
        }
    });
    s.open();
    while (!s.isDisposed()) {
        if (!d.readAndDispatch())
            d.sleep();
    }
    d.dispose();
}