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

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

Introduction

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

Prototype

public boolean readAndDispatch() 

Source Link

Document

Reads an event from the event queue, dispatches it appropriately, and returns true if there is potentially more work to do, or false if the caller can sleep until another event is placed on the event queue.

Usage

From source file:FormLayoutFormAttachmentSetButton.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    FormLayout layout = new FormLayout();
    layout.marginHeight = 5;//from www .j a  v  a  2 s. c  o m
    layout.marginWidth = 10;
    shell.setLayout(layout);

    Button one = new Button(shell, SWT.PUSH);
    one.setText("One");
    FormData data = new FormData();
    data.top = new FormAttachment(0, 5);
    data.left = new FormAttachment(0, 5);
    data.bottom = new FormAttachment(50, -5);
    data.right = new FormAttachment(50, -5);
    one.setLayoutData(data);

    shell.pack();
    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);// ww  w.j  av a  2s  . c  om

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

        }//  ww  w.  j a  va  2 s  .co  m

        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: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 a  v a2s. co m
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.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");

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

        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  ww.j a  v a 2 s.  c om*/
    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: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();/*www.j  ava 2 s. c o m*/
    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/*www .  j ava 2 s. c  o  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:MainClass.java

public static void main(String[] a) {

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

    shell.setSize(250, 200);/*  w  w  w . j  a va 2s.  c  o  m*/

    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: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);//from  w  w w. j ava  2s.co  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();
}