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

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

Introduction

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

Prototype

public Label(Composite parent, int style) 

Source Link

Document

Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.

Usage

From source file:ExampleGUI.java

public static void main(String[] args) {
    // create a shell...
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    shell.setText("KTable examples");

    // put a tab folder in it...
    TabFolder tabFolder = new TabFolder(shell, SWT.NONE);

    // Item 1: a Text Table
    TabItem item1 = new TabItem(tabFolder, SWT.NONE);
    item1.setText("Text Table");
    Composite comp1 = new Composite(tabFolder, SWT.NONE);
    item1.setControl(comp1);//from ww w  .  j ava 2  s.  c  o m
    comp1.setLayout(new FillLayout());

    // put a table in tabItem1...
    KTable table = new KTable(comp1, SWT.V_SCROLL | SWT.H_SCROLL);
    // table.setRowSelectionMode(true);
    table.setMultiSelectionMode(true);
    table.setModel(new KTableModelExample());
    table.addCellSelectionListener(new KTableCellSelectionListener() {
        public void cellSelected(int col, int row, int statemask) {
            System.out.println("Cell [" + col + ";" + row + "] selected.");
        }

        public void fixedCellSelected(int col, int row, int statemask) {
            System.out.println("Header [" + col + ";" + row + "] selected.");
        }

    });

    table.addCellResizeListener(new KTableCellResizeListener() {
        public void columnResized(int col, int newWidth) {
            System.out.println("Column " + col + " resized to " + newWidth);
        }

        public void rowResized(int newHeight) {
            System.out.println("Rows resized to " + newHeight);
        }

    });

    // Item 2: a Color Palette
    TabItem item2 = new TabItem(tabFolder, SWT.NONE);
    item2.setText("Color Palette");
    Composite comp2 = new Composite(tabFolder, SWT.NONE);
    item2.setControl(comp2);
    comp2.setLayout(new FillLayout());

    // put a table in tabItem2...
    final KTable table2 = new KTable(comp2, SWT.NONE);
    table2.setModel(new PaletteExampleModel());
    table2.setRowSelectionMode(false);
    table2.setMultiSelectionMode(false);
    final Label label = new Label(comp2, SWT.NONE);
    label.setText("Click a cell...");
    table2.addCellSelectionListener(new KTableCellSelectionAdapter() {
        public void cellSelected(int col, int row, int statemask) {
            RGB rgb = (RGB) table2.getModel().getContentAt(col, row);
            label.setText("R: " + rgb.red + "\nG: " + rgb.green + "\nB: " + rgb.blue);
        }
    });

    // Item 3: Town table
    TabItem item3 = new TabItem(tabFolder, SWT.NONE);
    item3.setText("Towns");
    Composite comp3 = new Composite(tabFolder, SWT.NONE);
    item3.setControl(comp3);
    comp3.setLayout(new FillLayout());

    // put a table in tabItem3...
    final KTable table3 = new KTable(comp3, SWT.FLAT | SWT.H_SCROLL);
    table3.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
    table3.setModel(new TownExampleModel());
    table3.setRowSelectionMode(true);
    table3.setMultiSelectionMode(false);

    // display the shell...
    shell.setSize(600, 600);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:MainClass.java

protected Control createContents(Composite parent) {
    Label label = new Label(parent, SWT.CENTER);
    label.setText("Hello, World");
    return label;
}

From source file:org.eclipse.swt.snippets.Snippet370.java

private static void createForLocale(Shell shell, Locale locale) {
    System.setProperty("swt.datetime.locale", locale.toLanguageTag());
    Composite composite = new Composite(shell, SWT.BORDER);
    composite.setLayout(new RowLayout(SWT.HORIZONTAL));
    new Label(composite, SWT.NONE).setText(locale.toLanguageTag());
    new DateTime(composite, SWT.DROP_DOWN);
    new DateTime(composite, SWT.SHORT);
    new DateTime(composite, SWT.TIME);
}

From source file:FormLayoutExample.java

FormLayoutExample() {
    d = new Display();
    s = new Shell(d);
    s.setSize(250, 250);/*from  w  ww .j  av  a2 s . co  m*/

    s.setText("A FormLayout Example");
    s.setLayout(new FormLayout());

    final Label l1 = new Label(s, SWT.RIGHT);
    l1.setText("First Name");
    FormData fd = new FormData();
    fd.top = new FormAttachment(10, 10);
    fd.left = new FormAttachment(0, 10);
    fd.bottom = new FormAttachment(30, 0);
    fd.right = new FormAttachment(40, 0);
    l1.setLayoutData(fd);

    final Label l2 = new Label(s, SWT.RIGHT);
    l2.setText("Last Name");
    fd = new FormData();
    fd.top = new FormAttachment(l1, 5);
    fd.left = new FormAttachment(0, 10);
    fd.bottom = new FormAttachment(40, 0);
    fd.right = new FormAttachment(40, 0);
    l2.setLayoutData(fd);

    final Text t1 = new Text(s, SWT.BORDER | SWT.SINGLE);
    fd = new FormData();
    fd.top = new FormAttachment(l1, 0, SWT.TOP);
    fd.left = new FormAttachment(l1, 10);
    t1.setLayoutData(fd);

    final Text t2 = new Text(s, SWT.BORDER | SWT.SINGLE);
    fd = new FormData();
    fd.top = new FormAttachment(l2, 0, SWT.TOP);
    fd.left = new FormAttachment(l2, 10);
    t2.setLayoutData(fd);

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

From source file:MouseListenerExample.java

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

    s.setSize(250, 200);//from   w ww  . j  a v  a 2s. 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:MouseEventExample.java

/**
 * MouseEventExample constructor//  w w w .  j a va 2  s.  com
 * 
 * @param shell the shell
 */
public MouseEventExample(Shell shell) {
    myLabel = new Label(shell, SWT.BORDER);
    myLabel.setText("I ain't afraid of any old mouse");
    shell.addMouseListener(this);
    shell.addMouseMoveListener(this);
    shell.addMouseTrackListener(this);
}

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 www. java 2s  .  c  o  m
    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:UserPassword.java

private void init() {
    (new Label(shell, SWT.NULL)).setText("User name: ");

    textUser = new Text(shell, SWT.SINGLE | SWT.BORDER);
    textUser.setText("default_user");
    textUser.setTextLimit(16);//  w w  w.  ja  v  a  2s.  c o m

    (new Label(shell, SWT.NULL)).setText("Password: ");

    textPassword = new Text(shell, SWT.SINGLE | SWT.BORDER);
    System.out.println(textPassword.getEchoChar());
    textPassword.setEchoChar('*');
}

From source file:ApplicationWindowJFrace.java

protected Control createContents(Composite parent) {
    // Create a Hello, World label
    Label label = new Label(parent, SWT.CENTER);
    label.setText("www.java2s.com");
    return label;
}

From source file:HelloWorld4.java

public Shell open(Display display) {
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    Label label = new Label(shell, SWT.CENTER);
    label.setText("Hello_world");
    shell.pack();/*  ww  w . ja  va2  s .  co  m*/
    shell.open();
    return shell;
}