List of usage examples for org.eclipse.swt.widgets Label Label
public Label(Composite parent, int style)
From source file:ShowPrograms.java
/** * Creates the main window's contents/*from w ww . ja va 2 s.c om*/ * * @param shell the main window */ private void createContents(Shell shell) { shell.setLayout(new GridLayout(2, false)); // Create the label and combo for the extensions new Label(shell, SWT.NONE).setText("Extension:"); Combo extensionsCombo = new Combo(shell, SWT.BORDER | SWT.READ_ONLY); extensionsCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // Create the label and the new Label(shell, SWT.NONE).setText("Program:"); final Label programName = new Label(shell, SWT.NONE); programName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // Fill the combo with the extensions on the system String[] extensions = Program.getExtensions(); for (int i = 0, n = extensions.length; i < n; i++) { extensionsCombo.add(extensions[i]); } // Add a handler to get the selected extension, look up the associated // program, and display the program's name extensionsCombo.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { Combo combo = (Combo) event.widget; // Get the program for the extension Program program = Program.findProgram(combo.getText()); // Display the program's name programName.setText(program == null ? "(None)" : program.getName()); } }); // Create a list box to show all the programs on the system List allPrograms = new List(shell, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); GridData data = new GridData(GridData.FILL_BOTH); data.horizontalSpan = 2; allPrograms.setLayoutData(data); // Put all the known programs into the list box Program[] programs = Program.getPrograms(); for (int i = 0, n = programs.length; i < n; i++) { String name = programs[i].getName(); allPrograms.add(name); allPrograms.setData(name, programs[i]); } // Add a field for a data file new Label(shell, SWT.NONE).setText("Data File:"); final Text dataFile = new Text(shell, SWT.BORDER); dataFile.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // Double-clicking a program in the list launches the program allPrograms.addMouseListener(new MouseAdapter() { public void mouseDoubleClick(MouseEvent event) { List list = (List) event.widget; if (list.getSelectionCount() > 0) { String programName = list.getSelection()[0]; Program program = (Program) list.getData(programName); program.execute(dataFile.getText()); } } }); // Let them use launch instead of execute Button launch = new Button(shell, SWT.PUSH); data = new GridData(GridData.FILL_HORIZONTAL); data.horizontalSpan = 2; launch.setLayoutData(data); launch.setText("Use Program.launch() instead of Program.execute()"); launch.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { // Use launch Program.launch(dataFile.getText()); } }); }
From source file:FormattedText.java
public FormattedText() { label = new Label(shell, SWT.BORDER | SWT.WRAP); label.setBackground(display.getSystemColor(SWT.COLOR_WHITE)); label.setText("Java UI Programming with SWT/JFace"); buttonColor = new Button(shell, SWT.PUSH); buttonColor.setText("Change color"); buttonColor.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { ColorDialog colorDialog = new ColorDialog(shell); if (color != null) colorDialog.setRGB(color.getRGB()); RGB value = colorDialog.open(); if (value != null) { if (color != null) color.dispose();/*from ww w . j a v a2 s . c o m*/ color = new Color(display, value); label.setForeground(color); } else { System.out.println("Setting foreground color action canceled."); } } }); buttonFont = new Button(shell, SWT.PUSH); buttonFont.setText("Change font"); buttonFont.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { FontDialog fontDialog = new FontDialog(shell); if (font != null) fontDialog.setFontList(font.getFontData()); FontData fontData = fontDialog.open(); if (fontData != null) { if (font != null) font.dispose(); font = new Font(display, fontData); label.setFont(font); } else { System.out.println("Setting font action canceled."); } } }); label.setBounds(0, 0, 300, 120); buttonColor.setBounds(50, 130, 90, 25); buttonFont.setBounds(160, 130, 90, 25); shell.setSize(300, 190); 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:BugReport.java
public BugReport() { shell.setLayout(new GridLayout(1, true)); shell.setImage(new Image(display, "java2s.gif")); shell.setText("Bug report page"); Group groupBug = new Group(shell, SWT.NULL); groupBug.setText("Bug details"); groupBug.setLayout(new GridLayout(2, false)); groupBug.setLayoutData(new GridData(GridData.FILL_BOTH)); new Label(groupBug, SWT.NULL).setText("Priority"); Combo combo = new Combo(groupBug, SWT.BORDER); combo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); new Label(groupBug, SWT.NULL).setText("Details"); Text text = new Text(groupBug, SWT.BORDER | SWT.MULTI); text.setLayoutData(new GridData(GridData.FILL_BOTH)); Group groupProxy = new Group(shell, SWT.NULL); groupProxy.setText("Connection setting"); groupProxy.setLayout(new GridLayout(2, false)); groupProxy.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); new Label(groupProxy, SWT.NULL).setText("Proxy host"); Text textHost = new Text(groupProxy, SWT.SINGLE | SWT.BORDER); textHost.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); new Label(groupProxy, SWT.NULL).setText("Proxy port"); Text textPort = new Text(groupProxy, SWT.SINGLE | SWT.BORDER); textPort.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); Button button = new Button(shell, SWT.PUSH); button.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER)); //button.setAlignment(SWT.CENTER); button.setText("Submit bug report"); shell.pack();//from w w w. j a v a 2 s .c om 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:ControlListenerExample.java
/** * Creates the main window's contents/*w w w . ja v a 2 s . com*/ * * @param shell the main window * @param image the image */ private void createContents(Shell shell, Image image) { shell.setLayout(new GridLayout()); // Create a label to hold the image Label label = new Label(shell, SWT.NONE); label.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); label.setImage(image); shell.setData(label); // Add the listener shell.addControlListener(new ControlAdapter() { public void controlResized(ControlEvent event) { // Get the event source (the shell) Shell shell = (Shell) event.getSource(); // Get the source's data (the label) Label label = (Label) shell.getData(); // Determine how big the shell should be to fit the image Rectangle rect = shell.getClientArea(); ImageData data = label.getImage().getImageData(); // If the shell is too small, hide the image if (rect.width < data.width || rect.height < data.height) { shell.setText("Too small."); label.setText("I'm melting!"); } else { // He fits! shell.setText("Happy Guy Fits!"); label.setImage(label.getImage()); } } }); }
From source file:Sample.java
public Sample() { shell.setText("Book Entry Demo"); GridLayout gridLayout = new GridLayout(4, false); gridLayout.verticalSpacing = 8;//from ww w . j a va 2 s.c o m shell.setLayout(gridLayout); // Title 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); // Author(s) 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); // Cover 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); // Details. 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 pubisher = new Text(shell, SWT.SINGLE | SWT.BORDER); pubisher.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"); // Abstract. 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. Button enter = new Button(shell, SWT.PUSH); enter.setText("Enter"); gridData = new GridData(); gridData.horizontalSpan = 4; gridData.horizontalAlignment = GridData.END; enter.setLayoutData(gridData); // Fill information. title.setText("Professional Java Interfaces with SWT/JFace"); authors.setText("Jack Li Guojie"); pages.setText("500pp"); pubisher.setText("John Wiley & Sons"); cover.setBackground(new Image(display, "java2s.gif")); bookAbstract.setText("This book provides a comprehensive guide for \n" + "you to create Java user interfaces with SWT/JFace. "); shell.pack(); 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:RoundRectangleExample.java
/** * Creates the main window's contents/*from w ww . ja v a 2s . c o m*/ * * @param shell the main window */ private void createContents(Shell shell) { shell.setLayout(new FillLayout(SWT.VERTICAL)); // Create the composite that holds the input fields Composite widgetComposite = new Composite(shell, SWT.NONE); widgetComposite.setLayout(new GridLayout(2, false)); // Create the input fields new Label(widgetComposite, SWT.NONE).setText("Arc Width:"); txtArcWidth = new Text(widgetComposite, SWT.BORDER); new Label(widgetComposite, SWT.NONE).setText("Arc Height"); txtArcHeight = new Text(widgetComposite, SWT.BORDER); // Create the button that launches the redraw Button button = new Button(widgetComposite, SWT.PUSH); button.setText("Redraw"); shell.setDefaultButton(button); // Create the canvas to draw the round rectangle on final Canvas drawingCanvas = new Canvas(shell, SWT.NONE); drawingCanvas.addPaintListener(new RoundRectangleExamplePaintListener()); // Add a handler to redraw the round rectangle when pressed button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { drawingCanvas.redraw(); } }); }
From source file:MainClass.java
public void createControl(Composite parent) { Label label = new Label(parent, SWT.CENTER); label.setText("Thanks!"); setControl(label);// www. ja v a2s.c om }
From source file:ChooseFont.java
/** * Creates the window contents//from w w w . ja va 2 s .com * * @param shell the parent shell */ private void createContents(final Shell shell) { shell.setLayout(new GridLayout(2, false)); final Label fontLabel = new Label(shell, SWT.NONE); fontLabel.setText("The selected font"); Button button = new Button(shell, SWT.PUSH); button.setText("Font..."); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { // Create the color-change dialog FontDialog dlg = new FontDialog(shell); // Pre-fill the dialog with any previous selection if (font != null) dlg.setFontList(fontLabel.getFont().getFontData()); if (color != null) dlg.setRGB(color.getRGB()); if (dlg.open() != null) { // Dispose of any fonts or colors we have created if (font != null) font.dispose(); if (color != null) color.dispose(); // Create the new font and set it into the label font = new Font(shell.getDisplay(), dlg.getFontList()); fontLabel.setFont(font); // Create the new color and set it color = new Color(shell.getDisplay(), dlg.getRGB()); fontLabel.setForeground(color); // Call pack() to resize the window to fit the new font shell.pack(); } } }); }
From source file:org.eclipse.swt.snippets.Snippet237.java
static void createChildren(Composite parent) { parent.setLayout(new RowLayout()); List list = new List(parent, SWT.BORDER | SWT.MULTI); list.add("List item 1"); list.add("List item 2"); Label label = new Label(parent, SWT.NONE); label.setText("Label"); Button button = new Button(parent, SWT.RADIO); button.setText("Radio Button"); button = new Button(parent, SWT.CHECK); button.setText("Check box Button"); button = new Button(parent, SWT.PUSH); button.setText("Push Button"); Text text = new Text(parent, SWT.BORDER); text.setText("Text"); }
From source file:org.eclipse.swt.examples.helloworld.HelloWorld2.java
public Shell open(Display display) { Shell shell = new Shell(display); Label label = new Label(shell, SWT.CENTER); label.setText(resHello.getString("Hello_world")); label.setBounds(shell.getClientArea()); shell.open();/*from ww w . ja va 2s .c o m*/ return shell; }