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:org.eclipse.swt.snippets.Snippet24.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 24");
    shell.setLayout(new RowLayout());
    Combo combo = new Combo(shell, SWT.NONE);
    combo.setItems("A-1", "B-1", "C-1");
    Text text = new Text(shell, SWT.SINGLE | SWT.BORDER);
    text.setText("some text");
    combo.addListener(SWT.DefaultSelection, e -> System.out.println(e.widget + " - Default Selection"));
    text.addListener(SWT.DefaultSelection, e -> System.out.println(e.widget + " - Default Selection"));
    shell.pack();//from  w  ww  . j  av  a  2s .com
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:RowLayoutFill.java

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

    RowLayout rowLayout = new RowLayout();
    rowLayout.fill = true; // Overriding default values.

    shell.setLayout(rowLayout);/*  w  w  w . j av a2s.  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:MouseListenerUsing.java

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

    shell.addMouseListener(new MouseListener() {

        public void mouseDoubleClick(MouseEvent arg0) {
            System.out.println("mouseDoubleClick");

        }//from   ww w. j a v  a 2  s  . c om

        public void mouseDown(MouseEvent arg0) {
            System.out.println("mouseDown");

        }

        public void mouseUp(MouseEvent arg0) {
            System.out.println("mouseUp");

        }
    });

    // Display the window
    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);//from  w  ww  .  ja v  a  2 s. c om

    shell.setLayout(new FillLayout());

    ScrolledComposite sc = new ScrolledComposite(shell, SWT.H_SCROLL | SWT.V_SCROLL);

    Composite child = new Composite(sc, SWT.NONE);
    child.setLayout(new FillLayout());

    new Button(child, SWT.PUSH).setText("One");
    new Button(child, SWT.PUSH).setText("Two");
    sc.setContent(child);

    sc.setMinSize(300, 300);

    sc.setExpandHorizontal(true);
    sc.setExpandVertical(true);

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

From source file:MouseTrackListenerUsing.java

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

    shell.addMouseTrackListener(new MouseTrackListener() {

        public void mouseEnter(MouseEvent arg0) {
            System.out.println("mouseEnter");

        }/*from w  ww  .  ja va 2s  . c  o  m*/

        public void mouseExit(MouseEvent arg0) {
            System.out.println("mouseExit");

        }

        public void mouseHover(MouseEvent arg0) {
            System.out.println("mouseHover");

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

From source file:DrawExample.java

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

    Canvas canvas = new Canvas(shell, SWT.NONE);
    canvas.setSize(150, 150);//  w  w w  .  j  a v  a 2 s.  com
    canvas.setLocation(20, 20);
    shell.open();
    shell.setSize(200, 220);

    GC gc = new GC(canvas);
    gc.drawRectangle(10, 10, 40, 45);
    gc.drawOval(65, 10, 30, 35);
    gc.drawLine(130, 10, 90, 80);
    gc.drawPolygon(new int[] { 20, 70, 45, 90, 70, 70 });
    gc.drawPolyline(new int[] { 10, 120, 70, 100, 100, 130, 130, 75 });
    gc.dispose();

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

From source file:cn.edu.thss.iise.bpmdemo.charts.SWTMultipleAxisDemo1.java

/**
 * Starting point for the demonstration application.
 *
 * @param args/* w  w  w  .jav  a  2 s .co m*/
 *            ignored.
 */
public static void main(String[] args) {
    final JFreeChart chart = createChart();
    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setSize(600, 300);
    shell.setLayout(new FillLayout());
    shell.setText("Test for jfreechart running with SWT");
    ChartComposite frame = new ChartComposite(shell, SWT.NONE, chart, true);
    frame.setDisplayToolTips(false);
    frame.setHorizontalAxisTrace(true);
    frame.setVerticalAxisTrace(true);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
}

From source file:StyledTextStatistics.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");

    System.out.println("Caret Offset: " + styledText.getCaretOffset());
    System.out.println("Total Lines of Text: " + styledText.getLineCount());
    System.out.println("Total Characters: " + styledText.getCharCount());
    System.out.println("Current Line: " + (styledText.getLineAtOffset(styledText.getCaretOffset()) + 1));

    styledText.setBounds(10, 10, 100, 100);
    shell.open();//from  w  ww .  j  a va  2  s .c  o m
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();

}

From source file:Snippet102.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    Tree tree = new Tree(shell, SWT.BORDER | SWT.MULTI);
    tree.setSize(200, 200);//  www . jav a2s.  c o  m
    for (int i = 0; i < 12; i++) {
        TreeItem item = new TreeItem(tree, SWT.NONE);
        item.setText("Item " + i);
    }
    TreeItem item = new TreeItem(tree, SWT.NONE, 1);
    TreeItem[] items = tree.getItems();
    int index = 0;
    while (index < items.length && items[index] != item)
        index++;
    item.setText("*** New Item " + index + " ***");
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:TabItemWithToolTipImage.java

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    final TabFolder tabFolder = new TabFolder(shell, SWT.BORDER);
    for (int i = 0; i < 6; i++) {
        TabItem item = new TabItem(tabFolder, SWT.NONE);
        item.setText("TabItem " + i);
        item.setToolTipText("This is my tab" + i);
        item.setImage(new Image(display, "yourFile.gif"));
        Button button = new Button(tabFolder, SWT.PUSH);
        button.setText("Page " + i);
        item.setControl(button);/*from  w w  w .jav  a2s  .co  m*/
    }
    tabFolder.pack();
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}