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 d = new Display();
    Shell s = new Shell(d);

    s.setText("A Tabbed Shell Example");
    final CoolBar bar = new CoolBar(s, SWT.BORDER);
    bar.setSize(280, 70);/*  w w w  .  j av  a  2s .c om*/
    bar.setLocation(0, 0);
    // final Image openIcon = new Image(d, "c:\\icons\\open.jpg");

    final CoolItem openCoolItem = new CoolItem(bar, SWT.NONE);
    final Button openBtn = new Button(bar, SWT.PUSH);
    // openBtn.setImage(openIcon);
    openBtn.pack();
    Point size = openBtn.getSize();
    openCoolItem.setControl(openBtn);
    openCoolItem.setSize(openCoolItem.computeSize(size.x, size.y));

    s.open();
    while (!s.isDisposed()) {
        if (!d.readAndDispatch())
            d.sleep();
    }
    d.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 w  w.  j  a va  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:ProgressBarExample.java

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

    // Create a smooth ProgressBar
    ProgressBar pb1 = new ProgressBar(shell, SWT.HORIZONTAL | SWT.SMOOTH);
    pb1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    pb1.setMinimum(0);/*from  w w w.  j a  v  a  2s .  c om*/
    pb1.setMaximum(30);

    // Start the first ProgressBar
    new LongRunningOperation(display, pb1).start();

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

From source file:TrackerMouseDown.java

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.open();/*from  w  w w .j  av a 2s . c o  m*/
    shell.addListener(SWT.MouseDown, new Listener() {
        public void handleEvent(Event e) {
            Tracker tracker = new Tracker(shell, SWT.NONE);
            tracker.setRectangles(new Rectangle[] { new Rectangle(e.x, e.y, 100, 100), });
            tracker.open();
        }
    });
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:Snippet50.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Shell");
    shell.setSize(200, 200);//from  w w w.  j a v a  2 s.c o  m
    shell.open();
    Shell dialog = new Shell(shell);
    dialog.setText("Dialog");
    dialog.setSize(200, 200);
    dialog.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:ShellEvents.java

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

    shell.addShellListener(new ShellListener() {

        public void shellActivated(ShellEvent event) {
            System.out.println("activate");
        }/*from w w w. j a va  2s .  c  o  m*/

        public void shellClosed(ShellEvent arg0) {
            System.out.println("close");
        }

        public void shellDeactivated(ShellEvent arg0) {
        }

        public void shellDeiconified(ShellEvent arg0) {
        }

        public void shellIconified(ShellEvent arg0) {
        }
    });

    shell.open();
    // Set up the event loop.
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            // If no more entries in event queue
            display.sleep();
        }
    }
    display.dispose();
}

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

    StyledTextPrintOptions options = new StyledTextPrintOptions();
    options.header = StyledTextPrintOptions.SEPARATOR + "myfile.txt" + StyledTextPrintOptions.SEPARATOR;
    options.footer = StyledTextPrintOptions.SEPARATOR + StyledTextPrintOptions.PAGE_TAG
            + StyledTextPrintOptions.SEPARATOR + "Confidential";
    options.printLineBackground = true;//from  w  w  w .  j a v  a  2s .  c o  m
    options.printTextBackground = true;
    options.printTextFontStyle = true;
    options.printTextForeground = true;
    styledText.print(new Printer(), options).run();

    styledText.setBounds(10, 10, 100, 100);
    shell.open();
    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();

    // Create the main window
    Shell shell = new Shell(display);

    Text fahrenheit = new Text(shell, SWT.BORDER);
    fahrenheit.setData("Type a temperature in Fahrenheit");
    fahrenheit.setBounds(20, 20, 100, 20);

    fahrenheit.addVerifyListener(new VerifyListener() {
        public void verifyText(VerifyEvent event) {
            // Assume we don't allow it
            event.doit = false;/*from w ww.java2  s  .c  om*/

            // Get the character typed
            char myChar = event.character;
            String text = ((Text) event.widget).getText();

            // Allow '-' if first character
            if (myChar == '-' && text.length() == 0)
                event.doit = true;

            // Allow 0-9
            if (Character.isDigit(myChar))
                event.doit = true;

            // Allow backspace
            if (myChar == '\b')
                event.doit = true;
        }

    });
    shell.open();

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

    // The SWT.BORDER style
    Decorations d = new Decorations(shell, SWT.ON_TOP);
    d.setLayoutData(new GridData(GridData.FILL_BOTH));
    d.setLayout(new FillLayout());
    Label l = new Label(d, SWT.CENTER);
    l.setText("SWT.ON_TOP");

    d.setBounds(20, 20, 100, 100);/*from w w  w . j a v  a 2  s. co  m*/

    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) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Sash One");

    // The SWT.BORDER style
    Decorations d = new Decorations(shell, SWT.MIN);
    d.setLayoutData(new GridData(GridData.FILL_BOTH));
    d.setLayout(new FillLayout());
    Label l = new Label(d, SWT.CENTER);
    l.setText("SWT.MIN");

    d.setBounds(20, 20, 100, 100);//  w ww.j a v a  2 s.com

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