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

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    FormLayout layout = new FormLayout();
    layout.marginHeight = 5;/*w ww. ja va 2  s  .c om*/
    layout.marginWidth = 10;
    shell.setLayout(layout);
    new Button(shell, SWT.PUSH).setText("Button");
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}

From source file:BackgroundColorImageInherit.java

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

    shell.setLayout(new RowLayout(SWT.VERTICAL));

    Color color = display.getSystemColor(SWT.COLOR_CYAN);

    Group group = new Group(shell, SWT.NONE);
    group.setText("SWT.INHERIT_NONE");
    group.setBackground(color);//from   w  w w  . j a  v a2  s.  c o  m
    group.setBackgroundMode(SWT.INHERIT_NONE);

    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) {
    Display d = new Display();
    Shell s = new Shell(d);

    final Text text1 = new Text(s, SWT.WRAP | SWT.BORDER);
    text1.setBounds(100, 50, 100, 20);/*from   w  ww  .j a v a 2s . c  o  m*/
    text1.setTextLimit(5);
    text1.setEchoChar('*');
    final Text text2 = new Text(s, SWT.SINGLE | SWT.BORDER);
    text2.setBounds(100, 75, 100, 20);
    text2.setTextLimit(30);

    FocusListener focusListener = new FocusListener() {
        public void focusGained(FocusEvent e) {
        }

        public void focusLost(FocusEvent e) {
            Text t = (Text) e.widget;
            if (t == text2) {
                if (t.getText().length() < 3) {
                    t.setFocus();
                }
            }
        }
    };
    text1.addFocusListener(focusListener);
    text2.addFocusListener(focusListener);

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

From source file:CheckBoxSelected.java

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

    Menu menuBar = new Menu(shell, SWT.BAR);

    Menu fileMenu = new Menu(menuBar);

    MenuItem fileItem = new MenuItem(menuBar, SWT.CASCADE | SWT.NO_RADIO_GROUP);
    fileItem.setText("File");
    fileItem.setMenu(fileMenu);/*ww  w.ja  v a2  s . c om*/

    MenuItem itema = new MenuItem(fileMenu, SWT.CHECK);
    itema.setText("Radio A");
    itema.setSelection(true);

    MenuItem itemb = new MenuItem(fileMenu, SWT.NONE);
    itemb.setText("Radio B");
    MenuItem itemc = new MenuItem(fileMenu, SWT.NONE);
    itemc.setText("Radio C");

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

    Text text1 = new Text(s, SWT.WRAP | SWT.BORDER);
    text1.setBounds(100, 50, 100, 20);//  w ww . j  av a  2s. com
    text1.setTextLimit(5);
    text1.setText("12345");
    Text text2 = new Text(s, SWT.SINGLE | SWT.BORDER);
    text2.setBounds(100, 75, 100, 20);
    text2.setTextLimit(30);

    FocusListener focusListener = new FocusListener() {
        public void focusGained(FocusEvent e) {
            Text t = (Text) e.widget;
            t.selectAll();
        }

        public void focusLost(FocusEvent e) {
            Text t = (Text) e.widget;
            if (t.getSelectionCount() > 0) {
                t.clearSelection();
            }
        }
    };
    text1.addFocusListener(focusListener);
    text2.addFocusListener(focusListener);

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

From source file:ScrollBarSelectionValue.java

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

    // Create a List with a vertical ScrollBar
    List list = new List(shell, SWT.V_SCROLL);

    // Add a bunch of items to it
    for (int i = 0; i < 500; i++) {
        list.add("A list item");
    }//from w ww . j  av  a  2s  .  c  o m

    // Get the ScrollBar
    ScrollBar sb = list.getVerticalBar();
    // Show the selection value
    System.out.println("Selection: " + sb.getSelection());

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

From source file:RowLayoutDefaultValue.java

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

    RowLayout rowLayout = new RowLayout();

    shell.setLayout(rowLayout);/*from w w  w. j av a  2  s . c  o m*/

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

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

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

From source file:PopupMenuAddTwoControls.java

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

    Composite c1 = new Composite(shell, SWT.BORDER);
    c1.setSize(100, 100);/*from  ww w.j  av  a  2s  .  c  o  m*/

    Composite c2 = new Composite(shell, SWT.BORDER);
    c2.setBounds(100, 0, 100, 100);

    Menu menu = new Menu(shell, SWT.POP_UP);
    MenuItem item = new MenuItem(menu, SWT.PUSH);
    item.setText("Popup");

    c1.setMenu(menu);
    c2.setMenu(menu);

    shell.setMenu(menu);
    shell.setSize(300, 300);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:FormLayoutFormDataWidthHeight.java

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

    shell.setLayout(new FormLayout());

    FormData formData = new FormData();
    formData.width = 100;/*from  w  ww  .ja v  a 2  s .co  m*/
    formData.height = 200;

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

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

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

From source file:TabListFocusTransfer.java

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

    Button b1 = new Button(shell, SWT.PUSH);
    b1.setText("1");
    Button b2 = new Button(shell, SWT.RADIO);
    b2.setText("2");
    Button b3 = new Button(shell, SWT.RADIO);
    b3.setText("3");
    Button b4 = new Button(shell, SWT.RADIO);
    b4.setText("4");
    Button b5 = new Button(shell, SWT.PUSH);
    b5.setText("5");

    Control[] tabList1 = new Control[] { b2, b1, b3, b5, b4 };
    shell.setTabList(tabList1);/*from  w ww.j  a  va  2  s. co m*/

    shell.pack();
    shell.open();

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