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

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

    Color red = display.getSystemColor(SWT.COLOR_RED);
    Color gray = display.getSystemColor(SWT.COLOR_GRAY);
    Color blue = display.getSystemColor(SWT.COLOR_BLUE);

    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());

    Table table = new Table(shell, SWT.BORDER);
    table.setBackground(gray);/*from w  w  w. j  ava  2  s  .  com*/

    TableColumn column1 = new TableColumn(table, SWT.NONE);
    TableColumn column2 = new TableColumn(table, SWT.NONE);
    TableColumn column3 = new TableColumn(table, SWT.NONE);

    TableItem item = new TableItem(table, SWT.NONE);
    item.setText(new String[] { "normal", "blue foreground", "red foreground" });
    item.setForeground(1, blue);
    item.setForeground(2, red);

    column1.pack();
    column2.pack();
    column3.pack();

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

From source file:ImageGrayScale.java

public static void main(String[] args) {
    final Display display = new Display();
    final 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) {
            Image image = new Image(display, "yourFile.gif");

            Image disable = new Image(display, image, SWT.IMAGE_GRAY);

            e.gc.drawImage(disable, 10, 10);

            e.gc.drawImage(image, 10, 50);

            image.dispose();//ww w .  j a v  a 2 s .  c o  m
            disable.dispose();
        }
    });

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

From source file:PopupListUsing.java

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

    // Create a button to launch the list
    Button button = new Button(shell, SWT.PUSH);
    button.setText("Push Me");
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            PopupList list = new PopupList(shell);

            list.setItems(new String[] { "A", "B", "C" });

            String selected = list.open(shell.getBounds());
            System.out.println(selected);
        }//from  w  w  w .j  a v a  2 s . c o m
    });

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

}

From source file:ButtonDefaultShell.java

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

    shell.setLayout(new RowLayout());

    final String[] ratings = new String[] { "A!", "B", "C" };
    final Button[] radios = new Button[ratings.length];
    for (int i = 0; i < ratings.length; i++) {
        radios[i] = new Button(shell, SWT.RADIO);
        radios[i].setText(ratings[i]);/* w  ww .  j ava2s  .  c  o m*/
    }

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

    Button rateButton = new Button(shell, SWT.PUSH);
    rateButton.setText("OK");
    rateButton.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            for (int i = 0; i < radios.length; i++) {
                if (radios[i].getSelection()) {
                    System.out.println(ratings[i]);
                }
            }
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            for (int i = 0; i < radios.length; i++) {
                if (radios[i].getSelection()) {
                    System.out.println(ratings[i]);
                }
            }
        }
    });

    shell.setDefaultButton(rateButton);

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

From source file:TableItemBackground.java

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

    Color red = display.getSystemColor(SWT.COLOR_RED);
    Color gray = display.getSystemColor(SWT.COLOR_GRAY);

    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());

    Table table = new Table(shell, SWT.BORDER);
    table.setBackground(gray);//from   w w  w  . java  2s  . c  o  m

    TableColumn column1 = new TableColumn(table, SWT.NONE);
    TableColumn column2 = new TableColumn(table, SWT.NONE);
    TableColumn column3 = new TableColumn(table, SWT.NONE);

    TableItem item = new TableItem(table, SWT.NONE);
    item.setText(new String[] { "entire", "row", "red background" });
    item.setBackground(red);

    column1.pack();
    column2.pack();
    column3.pack();

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

From source file:Snippet26.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    Combo combo = new Combo(shell, SWT.READ_ONLY);
    combo.setItems(new String[] { "A", "B", "C" });
    combo.setSize(200, 200);/*from w ww  .j av  a 2 s .c o  m*/
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:Snippet12.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    Text text = new Text(shell, SWT.BORDER | SWT.V_SCROLL);
    text.setBounds(10, 10, 100, 100);/* w  w  w  .j a v  a  2 s.  c o  m*/
    for (int i = 0; i < 16; i++) {
        text.append("Line " + i + "\n");
    }
    shell.open();
    text.setSelection(30, 38);
    System.out.println(text.getCaretLocation());
    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);
    shell.setText("Sash One");

    shell.setLayout(new FormLayout());

    Sash sash = new Sash(shell, SWT.VERTICAL);
    FormData data = new FormData();
    data.top = new FormAttachment(0, 0);
    data.bottom = new FormAttachment(100, 0);
    data.left = new FormAttachment(50, 0);
    sash.setLayoutData(data);/*from ww w.j  a  va  2  s .co  m*/

    // Create the first text box and attach its right edge
    // to the sash
    Text one = new Text(shell, SWT.BORDER);
    data = new FormData();
    data.top = new FormAttachment(0, 0);
    data.bottom = new FormAttachment(100, 0);
    data.left = new FormAttachment(0, 0);
    data.right = new FormAttachment(sash, 0);
    one.setLayoutData(data);

    Text two = new Text(shell, SWT.BORDER);
    data = new FormData();
    data.top = new FormAttachment(0, 0);
    data.bottom = new FormAttachment(100, 0);
    data.left = new FormAttachment(sash, 0);
    data.right = new FormAttachment(100, 0);
    two.setLayoutData(data);

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

From source file:ImageCopyCreation.java

public static void main(String[] args) {
    final Display display = new Display();
    final 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) {
            Image image = new Image(display, "yourFile.gif");

            Image copy = new Image(display, image, SWT.IMAGE_COPY);

            e.gc.drawImage(copy, 10, 10);

            e.gc.drawImage(copy, 10, 50);

            image.dispose();// w  w w.ja  v a2  s  .co  m
            copy.dispose();
        }
    });

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

From source file:PaintAWTInsideSWT.java

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    Composite composite = new Composite(shell, SWT.EMBEDDED);

    Frame frame = SWT_AWT.new_Frame(composite);
    Canvas canvas = new Canvas() {
        public void paint(Graphics g) {
            Dimension d = getSize();
            g.drawLine(0, 0, d.width, d.height);
        }/*from   w  w w  .  j  a  va 2 s.  c  o  m*/
    };
    frame.add(canvas);

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