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

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

    // Create a table and column
    final Table table = new Table(shell, SWT.VIRTUAL);
    table.setLinesVisible(true);// w  ww .  j ava 2s.  c o m
    table.setHeaderVisible(true);
    TableColumn tc = new TableColumn(table, SWT.NONE);
    tc.setText("Virtual Value");
    tc.setWidth(400);

    // Tell the table how many items it has
    table.setItemCount(100);

    // Provide the callback handler--this handler
    // is invoked when the table needs new rows
    table.addListener(SWT.SetData, new Listener() {
        public void handleEvent(Event event) {
            TableItem item = (TableItem) event.item;
            item.setText("data");
        }
    });
    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) {

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

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

    shell.setLayout(new FillLayout());

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

    canvas.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            // Do some drawing
            Rectangle rect = ((Canvas) e.widget).getBounds();
            e.gc.setForeground(e.display.getSystemColor(SWT.COLOR_RED));
            e.gc.drawFocus(5, 5, rect.width - 10, rect.height - 10);
            e.gc.drawText("www.java2s.com", 5, 50,
                    SWT.DRAW_MNEMONIC | SWT.DRAW_DELIMITER | SWT.DRAW_TAB | SWT.DRAW_TRANSPARENT);
        }
    });

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

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

        Composite composite = new Composite(tabFolder, SWT.NONE);
        composite.setLayout(new FillLayout());
        new Button(composite, SWT.PUSH).setText("Button One");
        new Button(composite, SWT.PUSH).setText("Button Two");
        new Button(composite, SWT.PUSH).setText("Button Three");
        item.setControl(composite);//from   w w w  .  j  ava2 s  .  co m

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

From source file:TextLayoutStrikeout.java

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display, SWT.SHELL_TRIM | SWT.DOUBLE_BUFFERED);
    shell.setText("Underline, Strike Out");
    Font font = shell.getFont();//from  w ww .  java  2s .  c  om
    String text = "text.text.text.";
    final TextLayout layout = new TextLayout(display);
    layout.setText(text);
    TextStyle style1 = new TextStyle(font, null, null);
    style1.strikeout = true;
    layout.setStyle(style1, 3, 5);

    shell.addListener(SWT.Paint, new Listener() {
        public void handleEvent(Event event) {
            Point point = new Point(10, 10);
            int width = shell.getClientArea().width - 2 * point.x;
            layout.setWidth(width);
            layout.draw(event.gc, point.x, point.y);
        }
    });

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

From source file:TextLayoutUnderline.java

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display, SWT.SHELL_TRIM | SWT.DOUBLE_BUFFERED);
    shell.setText("Underline, Strike Out");
    Font font = shell.getFont();//from  w  w w . j  a  v  a  2 s .c o m
    String text = "text.text.text.";
    final TextLayout layout = new TextLayout(display);
    layout.setText(text);
    TextStyle style1 = new TextStyle(font, null, null);
    style1.underline = true;
    layout.setStyle(style1, 3, 5);

    shell.addListener(SWT.Paint, new Listener() {
        public void handleEvent(Event event) {
            Point point = new Point(10, 10);
            int width = shell.getClientArea().width - 2 * point.x;
            layout.setWidth(width);
            layout.draw(event.gc, point.x, point.y);
        }
    });

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

From source file:GridLayoutComplex.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    GridLayout layout = new GridLayout();
    layout.numColumns = 3;//from  w  ww .jav a 2  s.com
    layout.makeColumnsEqualWidth = true;
    shell.setLayout(layout);

    // Create the big button in the upper left
    GridData data = new GridData(GridData.FILL_BOTH);
    data.widthHint = 200;
    Button one = new Button(shell, SWT.PUSH);
    one.setText("one");
    one.setLayoutData(data);

    // Create a composite to hold the three buttons in the upper right
    Composite composite = new Composite(shell, SWT.NONE);
    data = new GridData(GridData.FILL_BOTH);
    data.horizontalSpan = 2;
    composite.setLayoutData(data);
    layout = new GridLayout();
    layout.numColumns = 1;
    layout.marginHeight = 15;
    composite.setLayout(layout);

    // Create button "two"
    data = new GridData(GridData.FILL_BOTH);
    Button two = new Button(composite, SWT.PUSH);
    two.setText("two");
    two.setLayoutData(data);

    // Create button "three"
    data = new GridData(GridData.HORIZONTAL_ALIGN_CENTER);
    Button three = new Button(composite, SWT.PUSH);
    three.setText("three");
    three.setLayoutData(data);

    // Create button "four"
    data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
    Button four = new Button(composite, SWT.PUSH);
    four.setText("four");
    four.setLayoutData(data);

    // Create the long button across the bottom
    data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    data.grabExcessHorizontalSpace = true;
    data.horizontalSpan = 3;
    data.heightHint = 150;
    Button five = new Button(shell, SWT.PUSH);
    five.setText("five");
    five.setLayoutData(data);

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

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

    Button button = new Button(canvas, SWT.PUSH);
    button.setBounds(10, 10, 300, 40);//from  w  w w .  ja  v a2s .c om
    button.setText("You can place widgets on a canvas");

    canvas.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            Rectangle rect = ((Canvas) e.widget).getBounds();
            e.gc.setForeground(e.display.getSystemColor(SWT.COLOR_RED));
            e.gc.drawFocus(5, 5, rect.width - 10, rect.height - 10);
            e.gc.drawText("You can draw text directly on a canvas", 60, 60);
        }
    });

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

From source file:AccessibleListenerAdding.java

License:asdf

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

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

    Label label = new Label(shell, SWT.NONE);
    label.setText("asdf");

    Accessible accessible = label.getAccessible();
    accessible.addAccessibleListener(new AccessibleAdapter() {
        public void getName(AccessibleEvent e) {
            super.getName(e);
            e.result = "Speak this instead of the text";
            System.out.println("Accessible");

        }//from  w  w w  .j a  v a2  s. com
    });

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

    display.dispose();
}

From source file:FontDataConstruct.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) {

            Font font = new Font(shell.getDisplay(), new FontData("Helvetica", 18, SWT.NORMAL));
            e.gc.setFont(font);/*  ww w  .  j a  v  a2s  .c o m*/
            e.gc.drawText("My Text", 0, 0);
            font.dispose();

        }
    });

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