List of usage examples for org.eclipse.swt.widgets Label setText
public void setText(String text)
From source file:AdvancedBrowser.java
public AdvancedBrowser(String location) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Advanced Browser"); shell.setLayout(new FormLayout()); Composite controls = new Composite(shell, SWT.NONE); FormData data = new FormData(); data.top = new FormAttachment(0, 0); data.left = new FormAttachment(0, 0); data.right = new FormAttachment(100, 0); controls.setLayoutData(data);/*from w w w. j a v a 2 s .com*/ Label status = new Label(shell, SWT.NONE); data = new FormData(); data.left = new FormAttachment(0, 0); data.right = new FormAttachment(100, 0); data.bottom = new FormAttachment(100, 0); status.setLayoutData(data); final Browser browser = new Browser(shell, SWT.BORDER); data = new FormData(); data.top = new FormAttachment(controls); data.bottom = new FormAttachment(status); data.left = new FormAttachment(0, 0); data.right = new FormAttachment(100, 0); browser.setLayoutData(data); controls.setLayout(new GridLayout(7, false)); Button button = new Button(controls, SWT.PUSH); button.setText("Back"); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { browser.back(); } }); button = new Button(controls, SWT.PUSH); button.setText("Forward"); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { browser.forward(); } }); button = new Button(controls, SWT.PUSH); button.setText("Refresh"); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { browser.refresh(); } }); button = new Button(controls, SWT.PUSH); button.setText("Stop"); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { browser.stop(); } }); final Text url = new Text(controls, SWT.BORDER); url.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); url.setFocus(); button = new Button(controls, SWT.PUSH); button.setText("Go"); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { browser.setUrl(url.getText()); } }); Label throbber = new Label(controls, SWT.NONE); throbber.setText(AT_REST); shell.setDefaultButton(button); browser.addCloseWindowListener(new AdvancedCloseWindowListener()); browser.addLocationListener(new AdvancedLocationListener(url)); browser.addProgressListener(new AdvancedProgressListener(throbber)); browser.addStatusTextListener(new AdvancedStatusTextListener(status)); // Go to the initial URL if (location != null) { browser.setUrl(location); } shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:Menus.java
/** * Creates the left-half pop-up menu//from w w w . j av a 2 s. co m * * @param shell the main window */ private void createPopUpMenu(Shell shell) { // Create a composite that the pop-up menu will be // associated with Label label = new Label(shell, SWT.BORDER); label.setText("Pop-up Menu"); // Create the pop-up menu Menu menu = new Menu(label); // Create the images star = new Image(shell.getDisplay(), this.getClass().getResourceAsStream("java2s.gif")); circle = new Image(shell.getDisplay(), this.getClass().getResourceAsStream("java2s.gif")); square = new Image(shell.getDisplay(), this.getClass().getResourceAsStream("java2s.gif")); triangle = new Image(shell.getDisplay(), this.getClass().getResourceAsStream("java2s.gif")); // Create all the items in the pop-up menu MenuItem newItem = new MenuItem(menu, SWT.CASCADE); newItem.setText("New"); newItem.setImage(star); MenuItem refreshItem = new MenuItem(menu, SWT.NONE); refreshItem.setText("Refresh"); refreshItem.setImage(circle); MenuItem deleteItem = new MenuItem(menu, SWT.NONE); deleteItem.setText("Delete"); new MenuItem(menu, SWT.SEPARATOR); // Add a check menu item and select it MenuItem checkItem = new MenuItem(menu, SWT.CHECK); checkItem.setText("Check"); checkItem.setSelection(true); checkItem.setImage(square); // Add a push menu item MenuItem pushItem = new MenuItem(menu, SWT.PUSH); pushItem.setText("Push"); new MenuItem(menu, SWT.SEPARATOR); // Create some radio items MenuItem item1 = new MenuItem(menu, SWT.RADIO); item1.setText("Radio One"); item1.setImage(triangle); MenuItem item2 = new MenuItem(menu, SWT.RADIO); item2.setText("Radio Two"); MenuItem item3 = new MenuItem(menu, SWT.RADIO); item3.setText("Radio Three"); // Create a new radio group new MenuItem(menu, SWT.SEPARATOR); // Create some radio items MenuItem itema = new MenuItem(menu, SWT.RADIO); itema.setText("Radio A"); MenuItem itemb = new MenuItem(menu, SWT.RADIO); itemb.setText("Radio B"); MenuItem itemc = new MenuItem(menu, SWT.RADIO); itemc.setText("Radio C"); // Create the New item's dropdown menu Menu newMenu = new Menu(menu); newItem.setMenu(newMenu); // Create the items in the New dropdown menu MenuItem shortcutItem = new MenuItem(newMenu, SWT.NONE); shortcutItem.setText("Shortcut"); MenuItem iconItem = new MenuItem(newMenu, SWT.NONE); iconItem.setText("Icon"); // Set the pop-up menu as the pop-up for the label label.setMenu(menu); }
From source file:CoolBarExamples.java
public CoolBarExamples() { shell.setLayout(new GridLayout()); final CoolBar coolBar = new CoolBar(shell, SWT.NONE); coolBar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // cool item with a text field. CoolItem textItem = new CoolItem(coolBar, SWT.NONE); Text text = new Text(coolBar, SWT.BORDER | SWT.DROP_DOWN); text.setText("TEXT"); text.pack();//w w w . j a v a2 s . com Point size = text.getSize(); textItem.setControl(text); textItem.setSize(textItem.computeSize(size.x, size.y)); // cool item with a label. CoolItem labelItem = new CoolItem(coolBar, SWT.NONE); Label label = new Label(coolBar, SWT.NONE); label.setText("LABEL"); label.pack(); size = label.getSize(); labelItem.setControl(label); labelItem.setSize(textItem.computeSize(size.x, size.y)); // cool item with a button. CoolItem buttonItem = new CoolItem(coolBar, SWT.NONE | SWT.DROP_DOWN); Composite composite = new Composite(coolBar, SWT.NONE); composite.setLayout(new GridLayout(2, true)); Button button1 = new Button(composite, SWT.PUSH); button1.setText("Button 1"); button1.pack(); Button button2 = new Button(composite, SWT.PUSH); button2.setText("Button 2"); button2.pack(); composite.pack(); size = composite.getSize(); buttonItem.setControl(composite); buttonItem.setSize(buttonItem.computeSize(size.x, size.y)); // // Test cool item adding method. // Label label2 = new Label(coolBar, SWT.NONE); // label2.setText("label2"); // addControlToCoolBar(label2, SWT.DROP_DOWN, coolBar); try { setState(coolBar, new File("coolbar.state")); } catch (IOException e1) { e1.printStackTrace(); } shell.addListener(SWT.Close, new Listener() { public void handleEvent(Event event) { try { saveState(coolBar, new File("coolbar.state")); } catch (IOException e) { e.printStackTrace(); } } }); shell.setSize(300, 120); // 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:grafici.PazientiTimeSeriesChart.java
/** * A demonstration application showing how to create a simple time series * chart. This example uses monthly data. * * @param title the frame title./* w ww. ja v a 2 s. co m*/ */ public PazientiTimeSeriesChart(String title, Composite parent, int style, int tipo) { super(parent, style); Label titolo = new Label(this, SWT.NONE); titolo.setFont(new Font(titolo.getDisplay(), "arial", 15, SWT.BOLD)); titolo.setText(title); GridData gdLbl = new GridData(SWT.FILL); titolo.setLayoutData(gdLbl); Composite cmp = new Composite(this, SWT.FILL | SWT.EMBEDDED); GridData gdCmp = new GridData(SWT.FILL); gdCmp.horizontalAlignment = SWT.FILL; gdCmp.verticalAlignment = SWT.FILL; gdCmp.grabExcessHorizontalSpace = true; gdCmp.grabExcessVerticalSpace = true; cmp.setLayoutData(gdCmp); cmp.setLayout(new GridLayout(1, false)); JPanel chartPanel = createDemoPanel(tipo); Frame graphFrame = SWT_AWT.new_Frame(cmp); graphFrame.add(chartPanel); graphFrame.pack(); GridData gdThis = new GridData(SWT.FILL); gdThis.horizontalAlignment = SWT.FILL; gdThis.verticalAlignment = SWT.FILL; gdThis.grabExcessHorizontalSpace = true; gdThis.grabExcessVerticalSpace = true; this.setLayoutData(gdThis); this.setLayout(new GridLayout(1, false)); }
From source file:org.eclipse.swt.examples.addressbook.SearchDialog.java
/** * Class constructor that sets the parent shell and the table widget that * the dialog will search./*from ww w .ja v a 2 s. c o m*/ * * @param parent Shell * The shell that is the parent of the dialog. */ public SearchDialog(Shell parent) { shell = new Shell(parent, SWT.CLOSE | SWT.BORDER | SWT.TITLE); GridLayout layout = new GridLayout(); layout.numColumns = 2; shell.setLayout(layout); shell.setText(resAddressBook.getString("Search_dialog_title")); shell.addShellListener(ShellListener.shellClosedAdapter(e -> { // don't dispose of the shell, just hide it for later use e.doit = false; shell.setVisible(false); })); Label label = new Label(shell, SWT.LEFT); label.setText(resAddressBook.getString("Dialog_find_what")); searchText = new Text(shell, SWT.BORDER); GridData gridData = new GridData(GridData.FILL_HORIZONTAL); gridData.widthHint = 200; searchText.setLayoutData(gridData); searchText.addModifyListener(e -> { boolean enableFind = (searchText.getCharCount() != 0); findButton.setEnabled(enableFind); }); searchAreaLabel = new Label(shell, SWT.LEFT); searchArea = new Combo(shell, SWT.DROP_DOWN | SWT.READ_ONLY); gridData = new GridData(GridData.FILL_HORIZONTAL); gridData.widthHint = 200; searchArea.setLayoutData(gridData); matchCase = new Button(shell, SWT.CHECK); matchCase.setText(resAddressBook.getString("Dialog_match_case")); gridData = new GridData(); gridData.horizontalSpan = 2; matchCase.setLayoutData(gridData); matchWord = new Button(shell, SWT.CHECK); matchWord.setText(resAddressBook.getString("Dialog_match_word")); gridData = new GridData(); gridData.horizontalSpan = 2; matchWord.setLayoutData(gridData); Group direction = new Group(shell, SWT.NONE); gridData = new GridData(); gridData.horizontalSpan = 2; direction.setLayoutData(gridData); direction.setLayout(new FillLayout()); direction.setText(resAddressBook.getString("Dialog_direction")); Button up = new Button(direction, SWT.RADIO); up.setText(resAddressBook.getString("Dialog_dir_up")); up.setSelection(false); down = new Button(direction, SWT.RADIO); down.setText(resAddressBook.getString("Dialog_dir_down")); down.setSelection(true); Composite composite = new Composite(shell, SWT.NONE); gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL); gridData.horizontalSpan = 2; composite.setLayoutData(gridData); layout = new GridLayout(); layout.numColumns = 2; layout.makeColumnsEqualWidth = true; composite.setLayout(layout); findButton = new Button(composite, SWT.PUSH); findButton.setText(resAddressBook.getString("Dialog_find")); findButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); findButton.setEnabled(false); findButton.addSelectionListener(widgetSelectedAdapter(e -> { if (!findHandler.find()) { MessageBox box = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK | SWT.PRIMARY_MODAL); box.setText(shell.getText()); box.setMessage(resAddressBook.getString("Cannot_find") + "\"" + searchText.getText() + "\""); box.open(); } })); Button cancelButton = new Button(composite, SWT.PUSH); cancelButton.setText(resAddressBook.getString("Cancel")); cancelButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING)); cancelButton.addSelectionListener(widgetSelectedAdapter(e -> shell.setVisible(false))); shell.pack(); }
From source file:org.jcryptool.visual.verifiablesecretsharing.views.ReconstructionChartComposite.java
/** * Generates the head of the tab. The head has a title and a description. *//*from w ww .j av a 2 s . c om*/ private void createHead() { final Composite head = new Composite(this, SWT.NONE); head.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); head.setLayout(new GridLayout()); final Label label = new Label(head, SWT.NONE); label.setFont(FontService.getHeaderFont()); label.setText(Messages.VerifiableSecretSharingComposite_tab_title); stDescription = new StyledText(head, SWT.READ_ONLY | SWT.MULTI | SWT.WRAP); stDescription.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); if (reconstructedPolynom.toString().compareTo("0") == 0) { stDescription.setText(Messages.ChartComposite_noGraph); } else { stDescription.setText(reconstructedPolynom.toString()); } }
From source file:grafici.FattureTimeSeriesChart.java
/** * A demonstration application showing how to create a simple time series * chart. This example uses monthly data. * //from w w w. j av a 2 s . com * @param title * the frame title. */ public FattureTimeSeriesChart(String title, Composite parent, int style, int tipo) { super(parent, style); System.out.println(2); Label titolo = new Label(this, SWT.NONE); titolo.setFont(new Font(titolo.getDisplay(), "arial", 15, SWT.BOLD)); titolo.setText(title); GridData gdLbl = new GridData(SWT.FILL); titolo.setLayoutData(gdLbl); Composite cmp = new Composite(this, SWT.FILL | SWT.EMBEDDED); GridData gdCmp = new GridData(SWT.FILL); gdCmp.horizontalAlignment = SWT.FILL; gdCmp.verticalAlignment = SWT.FILL; gdCmp.grabExcessHorizontalSpace = true; gdCmp.grabExcessVerticalSpace = true; cmp.setLayoutData(gdCmp); cmp.setLayout(new GridLayout(1, false)); JPanel chartPanel = createPanel(tipo); Frame graphFrame = SWT_AWT.new_Frame(cmp); graphFrame.add(chartPanel); graphFrame.pack(); GridData gdThis = new GridData(SWT.FILL); gdThis.horizontalAlignment = SWT.FILL; gdThis.verticalAlignment = SWT.FILL; gdThis.grabExcessHorizontalSpace = true; gdThis.grabExcessVerticalSpace = true; this.setLayoutData(gdThis); this.setLayout(new GridLayout(1, false)); }
From source file:grafici.MediciTimeSeriesChart.java
/** * A demonstration application showing how to create a simple time series * chart. This example uses monthly data. * /*from www.ja v a2 s . com*/ * @param title * the frame title. */ public MediciTimeSeriesChart(String title, Composite parent, int style, int tipo) { super(parent, style); Label titolo = new Label(this, SWT.NONE); titolo.setFont(new Font(titolo.getDisplay(), "arial", 15, SWT.BOLD)); titolo.setText(title); GridData gdLbl = new GridData(SWT.FILL); titolo.setLayoutData(gdLbl); Composite cmp = new Composite(this, SWT.FILL | SWT.EMBEDDED); GridData gdCmp = new GridData(SWT.FILL); gdCmp.horizontalAlignment = SWT.FILL; gdCmp.verticalAlignment = SWT.FILL; gdCmp.grabExcessHorizontalSpace = true; gdCmp.grabExcessVerticalSpace = true; cmp.setLayoutData(gdCmp); cmp.setLayout(new GridLayout(1, false)); JPanel chartPanel = createDemoPanel(tipo); Frame graphFrame = SWT_AWT.new_Frame(cmp); graphFrame.add(chartPanel); graphFrame.pack(); GridData gdThis = new GridData(SWT.FILL); gdThis.horizontalAlignment = SWT.FILL; gdThis.verticalAlignment = SWT.FILL; gdThis.grabExcessHorizontalSpace = true; gdThis.grabExcessVerticalSpace = true; this.setLayoutData(gdThis); this.setLayout(new GridLayout(1, false)); }
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 ww w . j av a 2 s . co 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:grafici.PrenotazioneTimeSeriesChart.java
/** * A demonstration application showing how to create a simple time series * chart. This example uses monthly data. * /*from w ww .jav a2 s .c om*/ * @param title * the frame title. */ public PrenotazioneTimeSeriesChart(String title, Composite parent, int style, int tipo) { super(parent, style); Label titolo = new Label(this, SWT.NONE); titolo.setFont(new Font(titolo.getDisplay(), "arial", 15, SWT.BOLD)); titolo.setText(title); GridData gdLbl = new GridData(SWT.FILL); titolo.setLayoutData(gdLbl); Composite cmp = new Composite(this, SWT.FILL | SWT.EMBEDDED); GridData gdCmp = new GridData(SWT.FILL); gdCmp.horizontalAlignment = SWT.FILL; gdCmp.verticalAlignment = SWT.FILL; gdCmp.grabExcessHorizontalSpace = true; gdCmp.grabExcessVerticalSpace = true; cmp.setLayoutData(gdCmp); cmp.setLayout(new GridLayout(1, false)); JPanel chartPanel = createDemoPanel(tipo); Frame graphFrame = SWT_AWT.new_Frame(cmp); graphFrame.add(chartPanel); graphFrame.pack(); GridData gdThis = new GridData(SWT.FILL); gdThis.horizontalAlignment = SWT.FILL; gdThis.verticalAlignment = SWT.FILL; gdThis.grabExcessHorizontalSpace = true; gdThis.grabExcessVerticalSpace = true; this.setLayoutData(gdThis); this.setLayout(new GridLayout(1, false)); }