List of usage examples for org.eclipse.swt.widgets Label Label
public Label(Composite parent, int style)
From source file:SampleCombo.java
public SampleCombo() { init();/*from w ww .j a v a 2 s.c o m*/ shell.setLayout(new GridLayout(2, false)); (new Label(shell, SWT.NULL)).setText("Select your favorite programming language: "); //final CCombo combo = new CCombo(shell, SWT.FLAT); final Combo combo = new Combo(shell, SWT.NULL); String[] languages = new String[] { "Java", "C", "C++", "SmallTalk" }; Arrays.sort(languages); for (int i = 0; i < languages.length; i++) combo.add(languages[i]); //combo.add("Perl", 5); //combo.setItem(5, "Perl"); combo.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { System.out.println("Selected index: " + combo.getSelectionIndex() + ", selected item: " + combo.getItem(combo.getSelectionIndex()) + ", text content in the text field: " + combo.getText()); } public void widgetDefaultSelected(SelectionEvent e) { System.out.println("Default selected index: " + combo.getSelectionIndex() + ", selected item: " + (combo.getSelectionIndex() == -1 ? "<null>" : combo.getItem(combo.getSelectionIndex())) + ", text content in the text field: " + combo.getText()); String text = combo.getText(); if (combo.indexOf(text) < 0) { // Not in the list yet. combo.add(text); // Re-sort String[] items = combo.getItems(); Arrays.sort(items); combo.setItems(items); } } }); 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:CompViewer.java
public Ch3_Group(Composite parent) { super(parent, SWT.NONE); Group group = new Group(this, SWT.SHADOW_ETCHED_IN); group.setText("Group Label"); Label label = new Label(group, SWT.NONE); label.setText("Two buttons:"); label.setLocation(20, 20);/*from ww w. j a v a2 s . c om*/ label.pack(); Button button1 = new Button(group, SWT.PUSH); button1.setText("Push button"); button1.setLocation(20, 45); button1.pack(); Button button2 = new Button(group, SWT.CHECK); button2.setText("Check button"); button2.setBounds(20, 75, 90, 30); group.pack(); }
From source file:SampleList.java
public SampleList() { init();//from w ww .j a v a 2 s .c o m RowLayout rowLayout = new RowLayout(); shell.setLayout(rowLayout); (new Label(shell, SWT.NULL)).setText("What programming languages are you proficient in? "); final List list = new List(shell, SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL); String[] languages = new String[] { "Java", "C", "C++", "SmallTalk" }; for (int i = 0; i < languages.length; i++) list.add(languages[i]); list.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { System.err.println(list.getSelectionIndex()); int[] indices = list.getSelectionIndices(); String[] items = list.getSelection(); StringBuffer sb = new StringBuffer("Selected indices: "); for (int i = 0; i < indices.length; i++) { sb.append(indices[i]); sb.append("("); sb.append(items[i]); sb.append(")"); if (i == indices.length - 1) sb.append('.'); else sb.append(", "); } System.out.println(sb.toString()); } public void widgetDefaultSelected(SelectionEvent e) { int[] indices = list.getSelectionIndices(); String[] items = list.getSelection(); StringBuffer sb = new StringBuffer("Default selected indices: "); for (int i = 0; i < indices.length; i++) { sb.append(indices[i]); sb.append("("); sb.append(items[i]); sb.append(")"); if (i == indices.length - 1) sb.append('.'); else sb.append(", "); } System.out.println(sb.toString()); } }); list.selectAll(); //list.select(1); 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:RemarksText.java
public RemarksText() { shell.setLayout(new GridLayout(1, false)); (new Label(shell, SWT.NULL)).setText("Remarks:"); text = new Text(shell, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); text.setText("123456789"); text.setLayoutData(new GridData(GridData.FILL_BOTH)); System.out.println("getText: " + text.getText(1, 6)); char[] chars = text.getLineDelimiter().toCharArray(); for (int i = 0; i < chars.length; i++) { System.out.println("Line delimiter #" + i + ": " + Integer.toHexString(chars[i])); }/* w w w.j a v a 2 s.co m*/ text.getOrientation(); System.out.println("Number of chars: " + text.getCharCount()); System.out.println("Tabs: " + text.getTabs()); text.addVerifyListener(new VerifyListener() { public void verifyText(VerifyEvent e) { if (e.end == e.start) { if (e.character == ' ' && (e.stateMask & SWT.CTRL) != 0) { if (text.getText(e.end - 1, e.end - 1).equals("V")) { e.text = "erifyListener"; } else { e.doit = false; } } } } }); text.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { System.out.println("New character count: " + text.getCharCount()); } }); // text.append("a"); text.setSelection(1, 4); System.out.println("getSelection:\t" + text.getSelection()); System.out.println("getSelectionCount:\t" + text.getSelectionCount()); System.out.println("getSelectionText:\t" + text.getSelectionText()); //text.insert("ABC"); init(); // shell.pack(); shell.setSize(300, 150); 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:DirFileSelection.java
public DirFileSelection() { label = new Label(shell, SWT.BORDER | SWT.WRAP); label.setBackground(display.getSystemColor(SWT.COLOR_WHITE)); label.setText("Select a dir/file by clicking the buttons below."); buttonSelectDir = new Button(shell, SWT.PUSH); buttonSelectDir.setText("Select a directory"); buttonSelectDir.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { DirectoryDialog directoryDialog = new DirectoryDialog(shell); directoryDialog.setFilterPath(selectedDir); directoryDialog.setMessage("Please select a directory and click OK"); String dir = directoryDialog.open(); if (dir != null) { label.setText("Selected dir: " + dir); selectedDir = dir;/*from w ww . j a v a 2 s . c o m*/ } } }); buttonSelectFile = new Button(shell, SWT.PUSH); buttonSelectFile.setText("Select a file/multiple files"); buttonSelectFile.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { FileDialog fileDialog = new FileDialog(shell, SWT.MULTI); fileDialog.setFilterPath(fileFilterPath); fileDialog.setFilterExtensions(new String[] { "*.rtf", "*.html", "*.*" }); fileDialog.setFilterNames(new String[] { "Rich Text Format", "HTML Document", "Any" }); String firstFile = fileDialog.open(); if (firstFile != null) { fileFilterPath = fileDialog.getFilterPath(); String[] selectedFiles = fileDialog.getFileNames(); StringBuffer sb = new StringBuffer( "Selected files under dir " + fileDialog.getFilterPath() + ": \n"); for (int i = 0; i < selectedFiles.length; i++) { sb.append(selectedFiles[i] + "\n"); } label.setText(sb.toString()); } } }); label.setBounds(0, 0, 400, 60); buttonSelectDir.setBounds(0, 65, 200, 30); buttonSelectFile.setBounds(200, 65, 200, 30); 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:MainClass.java
protected Control createContents(Composite parent) { Composite container = new Composite(parent, SWT.NULL); this.getShell().setText("ButtonTest"); GridLayout layout = new GridLayout(); container.setLayout(layout);//from ww w. ja va 2 s .c o m layout.numColumns = 4; layout.verticalSpacing = 9; Label label; label = new Label(container, SWT.NONE); label.setText("Button Type"); label = new Label(container, SWT.NONE); label.setText("NONE"); label = new Label(container, SWT.NONE); label.setText("BORDER"); label = new Label(container, SWT.NONE); label.setText("FLAT"); createLabel(container, SWT.NONE, "Push"); createButton(container, SWT.PUSH, "button1"); createButton(container, SWT.BORDER, "button2"); createButton(container, SWT.FLAT, "button3"); createLabel(container, SWT.NONE, "Radio"); createButton(container, SWT.RADIO, "button1"); createButton(container, SWT.RADIO | SWT.BORDER, "button2"); createButton(container, SWT.RADIO | SWT.FLAT, "button3"); createLabel(container, SWT.NONE, "Toggle"); createButton(container, SWT.TOGGLE, "button1"); createButton(container, SWT.TOGGLE | SWT.BORDER, "button2"); createButton(container, SWT.TOGGLE | SWT.FLAT, "button3"); createLabel(container, SWT.NONE, "Check"); createButton(container, SWT.CHECK, "button1"); createButton(container, SWT.CHECK | SWT.BORDER, "button2"); createButton(container, SWT.CHECK | SWT.FLAT, "button3"); createLabel(container, SWT.NONE, "Arrow | Left"); createButton(container, SWT.ARROW | SWT.LEFT, "button1"); createButton(container, SWT.ARROW | SWT.LEFT | SWT.BORDER, "button2"); createButton(container, SWT.ARROW | SWT.LEFT | SWT.FLAT, "button3"); return container; }
From source file:WrapLines.java
public WrapLines() { shell.setLayout(new GridLayout(2, true)); (new Label(shell, SWT.NULL)).setText("SWT.BORDER |\nSWT.MUTLI"); (new Label(shell, SWT.NULL)).setText("SWT.BORDER |\nSWT.MUTLI |\nSWT.WRAP"); init();// w w w.j av a 2s . c o m GridData gridData = new GridData(GridData.FILL_BOTH); text1.setLayoutData(gridData); gridData = new GridData(GridData.FILL_BOTH); text2.setLayoutData(gridData); 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.examples.graphics.StarPolyTab.java
@Override public void createControlPanel(Composite parent) { new Label(parent, SWT.NONE).setText(GraphicsExample.getResourceString("FillRule")); //$NON-NLS-1$ fillRuleCb = new Combo(parent, SWT.DROP_DOWN); fillRuleCb.add("FILL_EVEN_ODD"); fillRuleCb.add("FILL_WINDING"); fillRuleCb.select(0);/* w ww .j ava2s .c o m*/ fillRuleCb.addListener(SWT.Selection, event -> example.redraw()); }
From source file:TemperatureConverter.java
public TemperatureConverter() { shell.setText("SWT Temperature Converter"); shell.setLayout(new GridLayout(4, false)); fahrenheitLabel = new Label(shell, SWT.NULL); fahrenheitLabel.setText("Fahrenheit: "); fahrenheitValue = new Text(shell, SWT.SINGLE | SWT.BORDER); celsiusLabel = new Label(shell, SWT.NULL); celsiusLabel.setText("Celsius: "); celsiusValue = new Text(shell, SWT.SINGLE | SWT.BORDER); messageLabel = new Label(shell, SWT.BORDER); GridData gridData = new GridData(GridData.FILL_BOTH); gridData.horizontalSpan = 4;/*from w w w . j av a 2 s . c om*/ messageLabel.setLayoutData(gridData); ModifyListener listener = new ModifyListener() { public void modifyText(ModifyEvent e) { valueChanged((Text) e.widget); } }; fahrenheitValue.addModifyListener(listener); celsiusValue.addModifyListener(listener); 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:MainClass.java
public void createContents(Shell shell, String location) { 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 a2 s . co m*/ 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)); if (location != null) { browser.setUrl(location); } }