Example usage for org.eclipse.swt.widgets Label setBounds

List of usage examples for org.eclipse.swt.widgets Label setBounds

Introduction

In this page you can find the example usage for org.eclipse.swt.widgets Label setBounds.

Prototype

public void setBounds(int x, int y, int width, int height) 

Source Link

Document

Sets the receiver's size and location to the rectangular area specified by the arguments.

Usage

From source file:LabelWrap.java

public LabelWrap() {
    Display display = new Display();
    Shell shell = new Shell(display);

    String text = "Professional Java Interfaces With SWT/JFace, by Jack Li Guojie";

    Label labelNoWrap = new Label(shell, SWT.BORDER);
    labelNoWrap.setText(text);//from  w  w  w  .  j  a  v a 2  s.c  om
    labelNoWrap.setBounds(10, 10, 100, 100);

    Label labelWrap = new Label(shell, SWT.WRAP | SWT.BORDER);
    labelWrap.setText(text);
    labelWrap.setBounds(120, 10, 100, 100);

    shell.pack();
    shell.open();
    //textUser.forceFocus();

    // 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:MouseListenerExample.java

public MouseListenerExample() {
    d = new Display();
    s = new Shell(d);

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

    s.setText("A MouseListener Example");
    s.open();

    s.addMouseListener(new MouseListener() {
        public void mouseDown(MouseEvent e) {
            Label l = new Label(s, SWT.FLAT);
            l.setText("Mouse Button Down at:" + e.x + " " + e.y);
            l.setBounds(e.x, e.y, 150, 15);

        }

        public void mouseUp(MouseEvent e) {
            Label l = new Label(s, SWT.FLAT);
            l.setText("Mouse Button up at:" + e.x + " " + e.y);
            l.setBounds(e.x, e.y, 150, 15);
        }

        public void mouseDoubleClick(MouseEvent e) {

        }
    });

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

From source file:LabelSeparator.java

public LabelSeparator() {
    init();/*from www .j a va2 s .  c o m*/
    // shell.setLayout(new RowLayout());

    Label label = new Label(shell, SWT.BORDER);
    // Label label = new Label(shell, SWT.SEPARATOR);
    label.setImage(image);
    label.setText("Label");
    label.setBounds(10, 10, 150, 150);

    CLabel clabel = new CLabel(shell, SWT.SHADOW_IN);
    clabel.setImage(image);
    clabel.setText("CLabel");
    clabel.setBounds(170, 10, 150, 150);

    shell.pack();
    shell.open();
    //textUser.forceFocus();

    // 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:WordJumbles.java

public WordJumbles(String word) {
    this.word = word;

    shell.setText("Word Jumbles");

    labelsRowOne = new Label[word.length()];
    labelsRowTwo = new Label[word.length()];

    int width = 40;

    // In the production version, you need to implement random permutation
    // generation.
    // Apache Jakarta Commons provides this function, see
    // org.apache.commons.math.random.RandomDataImpl
    int[] randomPermutation = { 5, 2, 6, 3, 1, 4, 0 };

    for (int i = 0; i < word.length(); i++) {
        final Label labelRowOne = new Label(shell, SWT.BORDER);
        labelsRowOne[i] = labelRowOne;/* w  w  w .  j  av  a2s .co m*/
        labelRowOne.setBounds(10 + width * i, 10, width - 5, width - 5);
        labelRowOne.setFont(font);
        labelRowOne.setText(word.charAt(randomPermutation[i]) + "");
        labelRowOne.setAlignment(SWT.CENTER);

        setDragSource(labelRowOne);
        //setDropTarget(labelRowOne);

        final Label labelRowTwo = new Label(shell, SWT.BORDER);
        labelsRowTwo[i] = labelRowTwo;
        labelRowTwo.setBounds(10 + width * i, 20 + width, width - 5, width - 5);
        labelRowTwo.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
        labelRowTwo.setFont(font);
        labelRowTwo.setAlignment(SWT.CENTER);

        setDragSource(labelRowTwo);
        //setDropTarget(labelRowTwo);
    }

    shell.pack();
    shell.open();
    //textUser.forceFocus();

    // 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:org.eclipse.swt.snippets.Snippet319.java

public void go() {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 319");
    shell.setBounds(10, 10, 600, 200);/*from w w  w. j  ava  2 s .  c  o m*/

    /* Create SWT controls and add drag source */
    final Label swtLabel = new Label(shell, SWT.BORDER);
    swtLabel.setBounds(10, 10, 580, 50);
    swtLabel.setText("SWT drag source");
    DragSource dragSource = new DragSource(swtLabel, DND.DROP_COPY);
    dragSource.setTransfer(new MyTypeTransfer());
    dragSource.addDragListener(new DragSourceAdapter() {
        @Override
        public void dragSetData(DragSourceEvent event) {
            MyType object = new MyType();
            object.name = "content dragged from SWT";
            object.time = System.currentTimeMillis();
            event.data = object;
        }
    });

    /* Create AWT/Swing controls */
    Composite embeddedComposite = new Composite(shell, SWT.EMBEDDED);
    embeddedComposite.setBounds(10, 100, 580, 50);
    embeddedComposite.setLayout(new FillLayout());
    Frame frame = SWT_AWT.new_Frame(embeddedComposite);
    final JLabel jLabel = new JLabel("AWT/Swing drop target");
    frame.add(jLabel);

    /* Register the custom data flavour */
    final DataFlavor flavor = new DataFlavor(MIME_TYPE, "MyType custom flavor");
    /*
     * Note that according to jre/lib/flavormap.properties, the preferred way to
     * augment the default system flavor map is to specify the AWT.DnD.flavorMapFileURL
     * property in an awt.properties file.
     *
     * This snippet uses the alternate approach below in order to provide a simple
     * stand-alone snippet that demonstrates the functionality.  This implementation
     * works well, but if the instanceof check below fails for some reason when used
     * in a different context then the drop will not be accepted.
     */
    FlavorMap map = SystemFlavorMap.getDefaultFlavorMap();
    if (map instanceof SystemFlavorMap) {
        SystemFlavorMap systemMap = (SystemFlavorMap) map;
        systemMap.addFlavorForUnencodedNative(MIME_TYPE, flavor);
    }

    /* add drop target */
    DropTargetListener dropTargetListener = new DropTargetAdapter() {
        @Override
        public void drop(DropTargetDropEvent dropTargetDropEvent) {
            try {
                dropTargetDropEvent.acceptDrop(DnDConstants.ACTION_COPY);
                ByteArrayInputStream inStream = (ByteArrayInputStream) dropTargetDropEvent.getTransferable()
                        .getTransferData(flavor);
                int available = inStream.available();
                byte[] bytes = new byte[available];
                inStream.read(bytes);
                MyType object = restoreFromByteArray(bytes);
                String string = object.name + ": " + new Date(object.time).toString();
                jLabel.setText(string);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    new DropTarget(jLabel, dropTargetListener);

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

From source file:SWTTextEditor.java

public void open() {
    Shell parent = getParent();// w w  w  . ja  v a 2 s .  c om
    final Shell dialog = new Shell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
    dialog.setSize(200, 100);
    dialog.setText("About");
    final Label l = new Label(dialog, SWT.NONE);
    l.setText("An SWT Text Editor");
    l.setBounds(43, 20, 100, 20);
    Button b = new Button(dialog, SWT.PUSH | SWT.BORDER);
    b.setText("OK");
    b.setBounds(80, 45, 40, 25);
    b.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            dialog.dispose();
        }
    });
    dialog.open();
    Display display = parent.getDisplay();
    while (!dialog.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
}

From source file:ProgressBarExamples.java

public ProgressBarExamples() {
    init();/*from   w  w  w  .  j  a  v a 2s.co  m*/

    ProgressBar pb1 = new ProgressBar(shell, SWT.NULL);
    final ProgressBar pb2 = new ProgressBar(shell, SWT.SMOOTH);
    ProgressBar pb3 = new ProgressBar(shell, SWT.INDETERMINATE);

    //      pb2.addPaintListener(new PaintListener() {
    //         public void paintControl(PaintEvent e) {
    //            Point point = pb2.getSize();
    //            
    //            Font font = new Font(shell.getDisplay(),"Courier",10,SWT.BOLD);
    //            e.gc.setFont(font);
    //            e.gc.setForeground(shell.getDisplay().getSystemColor(SWT.COLOR_WHITE));
    //            
    //            FontMetrics fontMetrics = e.gc.getFontMetrics();
    //            int stringWidth = fontMetrics.getAverageCharWidth() * 4;
    //            int stringHeight = fontMetrics.getHeight();
    //            
    //            e.gc.drawString("60%", (point.x-stringWidth)/2 , (point.y-stringHeight)/2, true);
    //            font.dispose();
    //         }
    //      });

    pb1.setSelection(60);
    pb2.setSelection(60);

    pb1.setBounds(100, 10, 200, 20);
    pb2.setBounds(100, 40, 200, 20);
    //pb3.setBounds(100, 70, 200, 20);

    Label label = new Label(shell, SWT.NULL);
    label.setText("(default)");
    Label label2 = new Label(shell, SWT.NULL);
    label2.setText("SWT.SMOOTH");

    label.setAlignment(SWT.RIGHT);
    label2.setAlignment(SWT.RIGHT);

    label.setBounds(10, 10, 80, 20);
    label2.setBounds(10, 40, 80, 20);

    shell.pack();
    shell.open();
    //textUser.forceFocus();

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

    display.dispose();
}