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

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

Introduction

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

Prototype

public boolean sleep() 

Source Link

Document

Causes the user-interface thread to sleep (that is, to be put in a state where it does not consume CPU cycles) until an event is received or it is otherwise awakened.

Usage

From source file:SWTGridLayout.java

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setSize(300, 200);//from w  w w.j  a  va  2 s . com
    shell.setLayout(new RowLayout());

    final Composite composite = new Composite(shell, SWT.NONE);
    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 4;
    composite.setLayout(gridLayout);

    for (int loopIndex = 0; loopIndex < 18; loopIndex++) {
        Button button = new Button(composite, SWT.PUSH);
        button.setText("Button " + loopIndex);
    }

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

From source file:CoolBarToolBar.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    CoolBar coolBar = new CoolBar(shell, SWT.BORDER);
    coolBar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    final CoolItem item = new CoolItem(coolBar, SWT.DROP_DOWN);
    item.setControl(createToolBar(coolBar));

    Control control = item.getControl();
    Point pt = control.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    pt = item.computeSize(pt.x, pt.y);//  ww w.  ja  v a2s. c  o  m
    item.setSize(pt);

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

From source file:TreeNodeCheckBoxAdd.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    Tree tree = new Tree(shell, SWT.CHECK | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    for (int i = 0; i < 12; i++) {
        TreeItem item = new TreeItem(tree, SWT.NONE);
        item.setText("Item " + i);
        for (int l = 0; l < 12; l++) {
            TreeItem litem = new TreeItem(item, SWT.NONE);
            litem.setText("Item " + i);
        }//from   w  ww  . j  av a 2s  . co  m

    }
    tree.setSize(100, 100);

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

From source file:Snippet108.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    Label label = new Label(shell, SWT.NONE);
    label.setText("Enter your name:");
    Text text = new Text(shell, SWT.BORDER);
    text.setLayoutData(new RowData(100, SWT.DEFAULT));
    Button ok = new Button(shell, SWT.PUSH);
    ok.setText("Ok");
    Button cancel = new Button(shell, SWT.PUSH);
    cancel.setText("Cancel");
    shell.setDefaultButton(cancel);//  w w  w.java  2 s  .  c o m
    shell.setLayout(new RowLayout());
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:StyledTextVerifyListenerEventInforation.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.addVerifyListener(new VerifyListener() {
        public void verifyText(VerifyEvent event) {
            System.out.println(event.start);
            System.out.println(event.end);
            System.out.println(event.text);
        }/*w  ww  . jav a  2  s.  c  om*/
    });

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

From source file:TextStrikeout.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("StyledText with underline and strike through");
    shell.setLayout(new FillLayout());
    StyledText text = new StyledText(shell, SWT.BORDER);
    text.setText("0123456789 ABCDEFGHIJKLM NOPQRSTUVWXYZ");

    // make 0123456789 appear strikeout
    StyleRange style1 = new StyleRange();
    style1.start = 0;/*  ww w .  j  a va  2s.  c o  m*/
    style1.length = 10;
    style1.strikeout = true;
    text.setStyleRange(style1);

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

From source file:TextUnderlined.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("StyledText with underline and strike through");
    shell.setLayout(new FillLayout());
    StyledText text = new StyledText(shell, SWT.BORDER);
    text.setText("0123456789 ABCDEFGHIJKLM NOPQRSTUVWXYZ");

    // make 0123456789 appear underlined
    StyleRange style1 = new StyleRange();
    style1.start = 0;//from ww  w.j  a  va 2  s  .co  m
    style1.length = 10;
    style1.underline = true;
    text.setStyleRange(style1);

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

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

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Excel Example");
    shell.setLayout(new FillLayout());
    try {/*w  w w.  j  a v  a 2 s. c  o  m*/
        OleFrame frame = new OleFrame(shell, SWT.NONE);
        new OleClientSite(frame, SWT.NONE, "Excel.Sheet");
        addFileMenu(frame);
    } catch (SWTError e) {
        System.out.println("Unable to open activeX control");
        display.dispose();
        return;
    }
    shell.setSize(800, 600);
    shell.open();

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

From source file:BrowserCloseWindowListener.java

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

    Browser browser = new Browser(shell, SWT.NONE);
    browser.setBounds(5, 5, 600, 600);/*from   w ww . j  av  a  2 s . c  o m*/

    browser.addCloseWindowListener(new CloseWindowListener() {
        public void close(WindowEvent event) {
            System.out.println("closing");
            Browser browser = (Browser) event.widget;
            Shell shell = browser.getShell();
            shell.close();
        }
    });

    browser.setUrl("http://java2s.com");
    shell.open();

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

From source file:GCFromEvent.java

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

    Canvas canvas = new Canvas(shell, SWT.NONE);

    canvas.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            e.gc.setForeground(e.display.getSystemColor(SWT.COLOR_RED));
            e.gc.drawFocus(5, 5, 200, 10);
            e.gc.drawText("You can draw text directly on a canvas", 60, 60);
        }//from  w  w  w .j av a2s .c  o  m
    });

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