Search in sources :

Example 41 with Display

use of org.eclipse.swt.widgets.Display in project yyl_example by Relucent.

the class MyStackLayout method open.

void open() {
    final Display display = Display.getDefault();
    final Shell shell = new Shell();
    final Composite comp1 = new Composite(shell, SWT.NONE);
    final StackLayout stackLayout = new StackLayout();
    final Text txt1 = new Text(comp1, SWT.BORDER);
    txt1.setText("T1");
    final Text txt2 = new Text(comp1, SWT.BORDER);
    txt2.setText("T2");
    Composite comp2 = new Composite(shell, SWT.NONE);
    comp2.setLayout(new RowLayout());
    Button btn1 = new Button(comp2, SWT.NONE);
    Button btn2 = new Button(comp2, SWT.NONE);
    btn1.setText("T1");
    btn2.setText("T2");
    comp1.setLayout(stackLayout);
    stackLayout.topControl = txt1;
    btn1.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            stackLayout.topControl = txt1;
            comp1.layout();
        }
    });
    btn2.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            stackLayout.topControl = txt2;
            comp1.layout();
        }
    });
    shell.setLayout(new FillLayout());
    shell.setText("StackLayout");
    shell.setSize(200, 200);
    //		shell.setMaximized(true);
    shell.layout();
    shell.open();
    while (!shell.isDisposed()) if (!display.readAndDispatch())
        display.sleep();
}
Also used : Shell(org.eclipse.swt.widgets.Shell) Composite(org.eclipse.swt.widgets.Composite) Button(org.eclipse.swt.widgets.Button) RowLayout(org.eclipse.swt.layout.RowLayout) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) StackLayout(org.eclipse.swt.custom.StackLayout) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Text(org.eclipse.swt.widgets.Text) FillLayout(org.eclipse.swt.layout.FillLayout) Display(org.eclipse.swt.widgets.Display)

Example 42 with Display

use of org.eclipse.swt.widgets.Display in project yyl_example by Relucent.

the class ImageCanvasTest method main.

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    ImageViewer ic = new ImageViewer(shell);
    shell.setLayout(new FillLayout());
    FileDialog dialog = new FileDialog(shell, SWT.OPEN);
    dialog.setText("Open an image file or cancel");
    String string = dialog.open();
    ImageLoader loader = new ImageLoader();
    ImageData[] imageDatas = loader.load(string);
    if (imageDatas.length == 0)
        return;
    else if (imageDatas.length == 1) {
        ic.setImage(imageDatas[0]);
    } else {
        ic.setImages(imageDatas, loader.repeatCount);
    }
    ic.pack();
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}
Also used : Shell(org.eclipse.swt.widgets.Shell) ImageData(org.eclipse.swt.graphics.ImageData) FillLayout(org.eclipse.swt.layout.FillLayout) ImageLoader(org.eclipse.swt.graphics.ImageLoader) FileDialog(org.eclipse.swt.widgets.FileDialog) Display(org.eclipse.swt.widgets.Display)

Example 43 with Display

use of org.eclipse.swt.widgets.Display in project yyl_example by Relucent.

the class ScrolledComposite_TEST method main.

public static void main(String[] args) {
    Display display = new Display();
    Color red = display.getSystemColor(SWT.COLOR_RED);
    Color blue = display.getSystemColor(SWT.COLOR_BLUE);
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    // set the size of the scrolled content - method 1
    final ScrolledComposite sc1 = new ScrolledComposite(shell, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    final Composite c1 = new Composite(sc1, SWT.NONE);
    sc1.setContent(c1);
    c1.setBackground(red);
    GridLayout layout = new GridLayout();
    layout.numColumns = 4;
    c1.setLayout(layout);
    Button b1 = new Button(c1, SWT.PUSH);
    b1.setText("first button");
    c1.setSize(c1.computeSize(SWT.DEFAULT, SWT.DEFAULT));
    // set the minimum width and height of the scrolled content - method 2
    final ScrolledComposite sc2 = new ScrolledComposite(shell, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    sc2.setExpandHorizontal(true);
    sc2.setExpandVertical(true);
    final Composite c2 = new Composite(sc2, SWT.NONE);
    sc2.setContent(c2);
    c2.setBackground(blue);
    layout = new GridLayout();
    layout.numColumns = 4;
    c2.setLayout(layout);
    Button b2 = new Button(c2, SWT.PUSH);
    b2.setText("first button");
    sc2.setMinSize(c2.computeSize(SWT.DEFAULT, SWT.DEFAULT));
    Button add = new Button(shell, SWT.PUSH);
    add.setText("add children");
    final int[] index = new int[] { 0 };
    add.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event e) {
            index[0]++;
            Button button = new Button(c1, SWT.PUSH);
            button.setText("button " + index[0]);
            // reset size of content so children can be seen - method 1
            c1.setSize(c1.computeSize(SWT.DEFAULT, SWT.DEFAULT));
            c1.layout();
            button = new Button(c2, SWT.PUSH);
            button.setText("button " + index[0]);
            // reset the minimum width and height so children can be seen - method 2
            sc2.setMinSize(c2.computeSize(SWT.DEFAULT, SWT.DEFAULT));
            c2.layout();
        }
    });
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}
Also used : Shell(org.eclipse.swt.widgets.Shell) GridLayout(org.eclipse.swt.layout.GridLayout) Listener(org.eclipse.swt.widgets.Listener) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) Button(org.eclipse.swt.widgets.Button) Color(org.eclipse.swt.graphics.Color) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) Event(org.eclipse.swt.widgets.Event) FillLayout(org.eclipse.swt.layout.FillLayout) Display(org.eclipse.swt.widgets.Display)

Example 44 with Display

use of org.eclipse.swt.widgets.Display in project yyl_example by Relucent.

the class DispelTreeEditorBug method open.

/**
	 * Open the window
	 */
public void open() {
    final Display display = Display.getDefault();
    createContents();
    shell.open();
    shell.layout();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
}
Also used : Display(org.eclipse.swt.widgets.Display)

Example 45 with Display

use of org.eclipse.swt.widgets.Display in project yyl_example by Relucent.

the class BrowserTest method main.

public static void main(String[] args) {
    Display display = Display.getDefault();
    Shell shell = new Shell();
    shell.setLayout(new FillLayout());
    Composite compCen = new Composite(shell, SWT.NONE);
    compCen.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    compCen.setLayout(new FillLayout());
    {
        Browser browser = new Browser(compCen, SWT.NONE);
        // 显示浏览器首页
        browser.setUrl("http://www.baidu.com/");
    //ScrolledComposite scrolledComposite = new ScrolledComposite(compCen, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    //scrolledComposite.setExpandHorizontal(true);
    //scrolledComposite.setExpandVertical(true);
    //scrolledComposite.setContent(widGraphPanel);
    }
    shell.layout();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) Composite(org.eclipse.swt.widgets.Composite) GridData(org.eclipse.swt.layout.GridData) FillLayout(org.eclipse.swt.layout.FillLayout) Display(org.eclipse.swt.widgets.Display) Browser(org.eclipse.swt.browser.Browser)

Aggregations

Display (org.eclipse.swt.widgets.Display)485 Shell (org.eclipse.swt.widgets.Shell)184 Point (org.eclipse.swt.graphics.Point)76 Test (org.junit.Test)63 FillLayout (org.eclipse.swt.layout.FillLayout)62 Color (org.eclipse.swt.graphics.Color)52 Button (org.eclipse.swt.widgets.Button)50 Rectangle (org.eclipse.swt.graphics.Rectangle)48 GridLayout (org.eclipse.swt.layout.GridLayout)43 Composite (org.eclipse.swt.widgets.Composite)43 GridData (org.eclipse.swt.layout.GridData)39 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)32 Image (org.eclipse.swt.graphics.Image)32 Label (org.eclipse.swt.widgets.Label)32 SWT (org.eclipse.swt.SWT)29 InvocationTargetException (java.lang.reflect.InvocationTargetException)28 StyledText (org.eclipse.swt.custom.StyledText)24 Text (org.eclipse.swt.widgets.Text)24 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)23 Font (org.eclipse.swt.graphics.Font)23