List of usage examples for org.eclipse.swt.widgets Label Label
public Label(Composite parent, int style)
From source file:MainClass.java
public static void main(String[] a) { Shell shell = new Shell(new Display()); final Shell dialog = new Shell(shell, SWT.APPLICATION_MODAL | SWT.DIALOG_TRIM); dialog.setText("Delete File"); dialog.setSize(250, 150);/*from w w w .j a v a2s . c o m*/ final Button buttonOK = new Button(dialog, SWT.PUSH); buttonOK.setText("OK"); buttonOK.setBounds(20, 55, 80, 25); Button buttonCancel = new Button(dialog, SWT.PUSH); buttonCancel.setText("Cancel"); buttonCancel.setBounds(120, 55, 80, 25); final Label label = new Label(dialog, SWT.NONE); label.setText("Delete the file?"); label.setBounds(20, 15, 100, 20); Listener listener = new Listener() { public void handleEvent(Event event) { if (event.widget == buttonOK) { System.out.println("OK"); } else { System.out.println("Cancel"); } dialog.close(); } }; buttonOK.addListener(SWT.Selection, listener); buttonCancel.addListener(SWT.Selection, listener); dialog.open(); }
From source file:ImageCreateForLable.java
public static void main(String[] args) { Image image;//from w w w .j av a2 s . c o m Image copy; Image disable; Image gray; Display display = new Display(); Shell shell = new Shell(display); shell.setText("Show Image Flags"); image = new Image(display, "yourFile.gif"); copy = new Image(display, image, SWT.IMAGE_COPY); disable = new Image(display, image, SWT.IMAGE_DISABLE); gray = new Image(display, image, SWT.IMAGE_GRAY); shell.setLayout(new FillLayout()); // Create labels to hold each image new Label(shell, SWT.NONE).setImage(image); new Label(shell, SWT.NONE).setImage(copy); new Label(shell, SWT.NONE).setImage(disable); new Label(shell, SWT.NONE).setImage(gray); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } image.dispose(); copy.dispose(); disable.dispose(); gray.dispose(); display.dispose(); }
From source file:Snippet34.java
public static void main(String[] args) { Display display = new Display(); Image image = new Image(display, 16, 16); Color color = display.getSystemColor(SWT.COLOR_RED); GC gc = new GC(image); gc.setBackground(color);// ww w. ja v a2 s . c o m gc.fillRectangle(image.getBounds()); gc.dispose(); Shell shell = new Shell(display); Label label = new Label(shell, SWT.BORDER); label.setImage(image); label.pack(); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } image.dispose(); display.dispose(); }
From source file:Snippet153.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setBounds(10, 10, 200, 200);//from ww w. j av a 2 s .c o m final ToolBar bar = new ToolBar(shell, SWT.BORDER); bar.setBounds(10, 10, 150, 50); final Label statusLine = new Label(shell, SWT.BORDER); statusLine.setBounds(10, 90, 150, 30); new ToolItem(bar, SWT.NONE).setText("item 1"); new ToolItem(bar, SWT.NONE).setText("item 2"); new ToolItem(bar, SWT.NONE).setText("item 3"); bar.addMouseMoveListener(new MouseMoveListener() { public void mouseMove(MouseEvent e) { ToolItem item = bar.getItem(new Point(e.x, e.y)); String name = ""; if (item != null) { name = item.getText(); } if (!statusText.equals(name)) { statusLine.setText(name); statusText = name; } } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:Snippet65.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); Label label = new Label(shell, SWT.WRAP); label.setText("This is a long text string that will wrap when the dialog is resized."); List list = new List(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); list.setItems(new String[] { "Item 1", "Item2" }); Button button1 = new Button(shell, SWT.PUSH); button1.setText("Ok"); Button button2 = new Button(shell, SWT.PUSH); button2.setText("Cancel"); final int insetX = 4, insetY = 4; FormLayout formLayout = new FormLayout(); formLayout.marginWidth = insetX;// ww w .j ava 2 s .c o m formLayout.marginHeight = insetY; shell.setLayout(formLayout); Point size = label.computeSize(SWT.DEFAULT, SWT.DEFAULT); final FormData labelData = new FormData(size.x, SWT.DEFAULT); labelData.left = new FormAttachment(0, 0); labelData.right = new FormAttachment(100, 0); label.setLayoutData(labelData); shell.addListener(SWT.Resize, new Listener() { public void handleEvent(Event e) { Rectangle rect = shell.getClientArea(); labelData.width = rect.width - insetX * 2; shell.layout(); } }); FormData button2Data = new FormData(); button2Data.right = new FormAttachment(100, -insetX); button2Data.bottom = new FormAttachment(100, 0); button2.setLayoutData(button2Data); FormData button1Data = new FormData(); button1Data.right = new FormAttachment(button2, -insetX); button1Data.bottom = new FormAttachment(100, 0); button1.setLayoutData(button1Data); FormData listData = new FormData(); listData.left = new FormAttachment(0, 0); listData.right = new FormAttachment(100, 0); listData.top = new FormAttachment(label, insetY); listData.bottom = new FormAttachment(button2, -insetY); list.setLayoutData(listData); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:GridLayoutDialog.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); Label labelUser;/*w w w . ja v a 2 s. co m*/ Label labelFile; final Text textUser; final Text textFile; Button buttonBrowseFile; Button buttonUpload; GridLayout gridLayout = new GridLayout(3, false); shell.setLayout(gridLayout); labelUser = new Label(shell, SWT.NULL); GridData gridData = new GridData(GridData.FILL_HORIZONTAL); gridData.grabExcessHorizontalSpace = true; textUser = new Text(shell, SWT.SINGLE | SWT.BORDER); textUser.setLayoutData(gridData); new Label(shell, SWT.NULL); // 2nd row. labelFile = new Label(shell, SWT.NULL); gridData = new GridData(GridData.FILL_HORIZONTAL); gridData.grabExcessHorizontalSpace = true; textFile = new Text(shell, SWT.SINGLE | SWT.BORDER); textFile.setLayoutData(gridData); buttonBrowseFile = new Button(shell, SWT.PUSH); // last row. gridData = new GridData(); gridData.horizontalSpan = 3; gridData.horizontalAlignment = GridData.CENTER; buttonUpload = new Button(shell, SWT.PUSH); buttonUpload.setLayoutData(gridData); labelUser.setText("User name: "); labelFile.setText("Photo: "); buttonBrowseFile.setText("Browse"); buttonUpload.setText("Upload"); buttonBrowseFile.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { FileDialog dialog = new FileDialog(shell, SWT.OPEN); String file = dialog.open(); if (file != null) { textFile.setText(file); } } }); buttonUpload.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { System.out.println(textUser.getText()); System.out.println(textFile.getText()); shell.dispose(); } }); shell.pack(); shell.open(); textUser.forceFocus(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:Snippet152.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); FormLayout layout = new FormLayout(); shell.setLayout(layout);/* ww w. j a va2 s . c o m*/ final Label label = new Label(shell, SWT.BORDER); Listener armListener = new Listener() { public void handleEvent(Event event) { MenuItem item = (MenuItem) event.widget; label.setText(item.getText()); label.update(); } }; Listener showListener = new Listener() { public void handleEvent(Event event) { Menu menu = (Menu) event.widget; MenuItem item = menu.getParentItem(); if (item != null) { label.setText(item.getText()); label.update(); } } }; Listener hideListener = new Listener() { public void handleEvent(Event event) { label.setText(""); label.update(); } }; FormData labelData = new FormData(); labelData.left = new FormAttachment(0); labelData.right = new FormAttachment(100); labelData.bottom = new FormAttachment(100); label.setLayoutData(labelData); Menu menuBar = new Menu(shell, SWT.BAR); shell.setMenuBar(menuBar); MenuItem fileItem = new MenuItem(menuBar, SWT.CASCADE); fileItem.setText("File"); fileItem.addListener(SWT.Arm, armListener); MenuItem editItem = new MenuItem(menuBar, SWT.CASCADE); editItem.setText("Edit"); editItem.addListener(SWT.Arm, armListener); Menu fileMenu = new Menu(shell, SWT.DROP_DOWN); fileMenu.addListener(SWT.Hide, hideListener); fileMenu.addListener(SWT.Show, showListener); fileItem.setMenu(fileMenu); String[] fileStrings = { "New", "Close", "Exit" }; for (int i = 0; i < fileStrings.length; i++) { MenuItem item = new MenuItem(fileMenu, SWT.PUSH); item.setText(fileStrings[i]); item.addListener(SWT.Arm, armListener); } Menu editMenu = new Menu(shell, SWT.DROP_DOWN); editMenu.addListener(SWT.Hide, hideListener); editMenu.addListener(SWT.Show, showListener); String[] editStrings = { "Cut", "Copy", "Paste" }; editItem.setMenu(editMenu); for (int i = 0; i < editStrings.length; i++) { MenuItem item = new MenuItem(editMenu, SWT.PUSH); item.setText(editStrings[i]); item.addListener(SWT.Arm, armListener); } shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:GridLayoutSimpleDmo.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); GridLayout gridLayout = new GridLayout(4, false); gridLayout.verticalSpacing = 8;//from w ww .j a v a 2 s .c om shell.setLayout(gridLayout); Label label = new Label(shell, SWT.NULL); label.setText("Title: "); Text title = new Text(shell, SWT.SINGLE | SWT.BORDER); GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL); gridData.horizontalSpan = 3; title.setLayoutData(gridData); label = new Label(shell, SWT.NULL); label.setText("Author(s): "); Text authors = new Text(shell, SWT.SINGLE | SWT.BORDER); gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL); gridData.horizontalSpan = 3; authors.setLayoutData(gridData); label = new Label(shell, SWT.NULL); label.setText("Cover: "); gridData = new GridData(); gridData.verticalSpan = 3; label.setLayoutData(gridData); CLabel cover = new CLabel(shell, SWT.NULL); gridData = new GridData(GridData.FILL_HORIZONTAL); gridData.horizontalSpan = 1; gridData.verticalSpan = 3; gridData.heightHint = 100; gridData.widthHint = 100; cover.setLayoutData(gridData); label = new Label(shell, SWT.NULL); label.setText("Pages"); Text pages = new Text(shell, SWT.SINGLE | SWT.BORDER); pages.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); label = new Label(shell, SWT.NULL); label.setText("Publisher"); Text publisher = new Text(shell, SWT.SINGLE | SWT.BORDER); publisher.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); label = new Label(shell, SWT.NULL); label.setText("Rating"); Combo rating = new Combo(shell, SWT.READ_ONLY); rating.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); rating.add("5"); rating.add("4"); rating.add("3"); rating.add("2"); rating.add("1"); label = new Label(shell, SWT.NULL); label.setText("Abstract:"); Text bookAbstract = new Text(shell, SWT.WRAP | SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL); gridData.horizontalSpan = 3; gridData.grabExcessVerticalSpace = true; bookAbstract.setLayoutData(gridData); Button enter = new Button(shell, SWT.PUSH); enter.setText("Enter"); gridData = new GridData(); gridData.horizontalSpan = 4; gridData.horizontalAlignment = GridData.END; enter.setLayoutData(gridData); title.setText("Professional Java Interfaces with SWT/JFace"); authors.setText("Jack Li Guojie"); pages.setText("500pp"); publisher.setText("John Wiley & Sons"); cover.setBackground(new Image(display, "yourFile.gif")); bookAbstract.setText("SWT/JFace. "); shell.setSize(450, 400); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:Snippet78.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setLayout(new FillLayout()); final Label label1 = new Label(shell, SWT.BORDER); label1.setText("TEXT"); final Label label2 = new Label(shell, SWT.BORDER); setDragDrop(label1);/*w ww. j ava2 s .c o m*/ setDragDrop(label2); shell.setSize(200, 200); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet37.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 37"); shell.setLayout(new FillLayout()); new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL); new Label(shell, SWT.SEPARATOR | SWT.VERTICAL); shell.setSize(200, 200);//www. j a va2 s. c o m shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }