List of usage examples for org.eclipse.swt.custom StyledText setText
public void setText(String text)
From source file:TextAroundBox.java
public static void main(String[] args) { final Display display = new Display(); final Color RED = display.getSystemColor(SWT.COLOR_RED); Shell shell = new Shell(display); shell.setBounds(10, 10, 250, 250);/* w w w. j ava 2s .co m*/ final StyledText text = new StyledText(shell, SWT.NONE); text.setBounds(10, 10, 200, 200); text.addListener(SWT.Paint, new Listener() { public void handleEvent(Event event) { String contents = text.getText(); int stringWidth = event.gc.stringExtent(SEARCH_STRING).x; int lineHeight = text.getLineHeight(); event.gc.setForeground(RED); int index = contents.indexOf(SEARCH_STRING); while (index != -1) { Point topLeft = text.getLocationAtOffset(index); event.gc.drawRectangle(topLeft.x - 1, topLeft.y, stringWidth + 1, lineHeight - 1); index = contents.indexOf(SEARCH_STRING, index + 1); } } }); text.setText("This demonstrates drawing a box\naround every occurrence of the word\nbox in the StyledText"); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet222.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("StyledText Bullet Example"); shell.setLayout(new FillLayout()); final StyledText styledText = new StyledText(shell, SWT.FULL_SELECTION | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL); StringBuilder text = new StringBuilder(); text.append("Here is StyledText with some bulleted lists:\n\n"); for (int i = 0; i < 4; i++) text.append("Red Bullet List Item " + i + "\n"); text.append("\n"); for (int i = 0; i < 2; i++) text.append("Numbered List Item " + i + "\n"); for (int i = 0; i < 4; i++) text.append("Sub List Item " + i + "\n"); for (int i = 0; i < 2; i++) text.append("Numbered List Item " + (2 + i) + "\n"); text.append("\n"); for (int i = 0; i < 4; i++) text.append("Custom Draw List Item " + i + "\n"); styledText.setText(text.toString()); StyleRange style0 = new StyleRange(); style0.metrics = new GlyphMetrics(0, 0, 40); style0.foreground = display.getSystemColor(SWT.COLOR_RED); Bullet bullet0 = new Bullet(style0); StyleRange style1 = new StyleRange(); style1.metrics = new GlyphMetrics(0, 0, 50); style1.foreground = display.getSystemColor(SWT.COLOR_BLUE); Bullet bullet1 = new Bullet(ST.BULLET_NUMBER | ST.BULLET_TEXT, style1); bullet1.text = "."; StyleRange style2 = new StyleRange(); style2.metrics = new GlyphMetrics(0, 0, 80); style2.foreground = display.getSystemColor(SWT.COLOR_GREEN); Bullet bullet2 = new Bullet(ST.BULLET_TEXT, style2); bullet2.text = "\u2713"; StyleRange style3 = new StyleRange(); style3.metrics = new GlyphMetrics(0, 0, 50); Bullet bullet3 = new Bullet(ST.BULLET_CUSTOM, style2); styledText.setLineBullet(2, 4, bullet0); styledText.setLineBullet(7, 2, bullet1); styledText.setLineBullet(9, 4, bullet2); styledText.setLineBullet(13, 2, bullet1); styledText.setLineBullet(16, 4, bullet3); styledText.addPaintObjectListener(event -> { Display display1 = event.display; StyleRange style = event.style;//from w ww . ja v a 2 s.com Font font = style.font; if (font == null) font = styledText.getFont(); TextLayout layout = new TextLayout(display1); layout.setAscent(event.ascent); layout.setDescent(event.descent); layout.setFont(font); layout.setText("\u2023 1." + event.bulletIndex + ")"); layout.draw(event.gc, event.x + 10, event.y); layout.dispose(); }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:StyledTextBulletedList.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("StyledText Bullet Example"); shell.setLayout(new FillLayout()); final StyledText styledText = new StyledText(shell, SWT.FULL_SELECTION | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL); StringBuffer text = new StringBuffer(); text.append("Here is StyledText with some bulleted lists:\n\n"); for (int i = 0; i < 4; i++) text.append("Red Bullet List Item " + i + "\n"); text.append("\n"); for (int i = 0; i < 2; i++) text.append("Numbered List Item " + i + "\n"); for (int i = 0; i < 4; i++) text.append("Sub List Item " + i + "\n"); for (int i = 0; i < 2; i++) text.append("Numbered List Item " + (2 + i) + "\n"); text.append("\n"); for (int i = 0; i < 4; i++) text.append("Custom Draw List Item " + i + "\n"); styledText.setText(text.toString()); StyleRange style0 = new StyleRange(); style0.metrics = new GlyphMetrics(0, 0, 40); style0.foreground = display.getSystemColor(SWT.COLOR_RED); Bullet bullet0 = new Bullet(style0); StyleRange style1 = new StyleRange(); style1.metrics = new GlyphMetrics(0, 0, 50); style1.foreground = display.getSystemColor(SWT.COLOR_BLUE); Bullet bullet1 = new Bullet(ST.BULLET_NUMBER | ST.BULLET_TEXT, style1); bullet1.text = "."; StyleRange style2 = new StyleRange(); style2.metrics = new GlyphMetrics(0, 0, 80); style2.foreground = display.getSystemColor(SWT.COLOR_GREEN); Bullet bullet2 = new Bullet(ST.BULLET_TEXT, style2); bullet2.text = "\u2713"; StyleRange style3 = new StyleRange(); style3.metrics = new GlyphMetrics(0, 0, 50); Bullet bullet3 = new Bullet(ST.BULLET_CUSTOM, style2); styledText.setLineBullet(2, 4, bullet0); styledText.setLineBullet(7, 2, bullet1); styledText.setLineBullet(9, 4, bullet2); styledText.setLineBullet(13, 2, bullet1); styledText.setLineBullet(16, 4, bullet3); styledText.addPaintObjectListener(new PaintObjectListener() { public void paintObject(PaintObjectEvent event) { Display display = event.display; StyleRange style = event.style; Font font = style.font; if (font == null) font = styledText.getFont(); TextLayout layout = new TextLayout(display); layout.setAscent(event.ascent); layout.setDescent(event.descent); layout.setFont(font);//w w w.j a va 2s . c o m layout.setText("\u2023 1." + event.bulletIndex + ")"); layout.draw(event.gc, event.x + 10, event.y); layout.dispose(); } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:StyleRangeTest.java
/** * Creates the main window contents//from w w w. j a va 2 s. c o m * * @param shell the main window */ private void createContents(Shell shell) { shell.setLayout(new FillLayout()); // Create the StyledText StyledText styledText = new StyledText(shell, SWT.BORDER); // Set the text styledText.setText("Go Gators"); /* * The multiple setStyleRange() method // Turn all of the text orange, with * the default background color styledText.setStyleRange(new StyleRange(0, 9, * orange, null)); * // Turn "Gators" blue styledText.setStyleRange(new StyleRange(3, 6, blue, * null)); */ /* * The setStyleRanges() method // Create the array to hold the StyleRanges * StyleRange[] ranges = new StyleRange[2]; * // Create the first StyleRange, making sure not to overlap. Include the * space. ranges[0] = new StyleRange(0, 3, orange, null); * // Create the second StyleRange ranges[1] = new StyleRange(3, 6, blue, * null); * // Replace all the StyleRanges for the StyledText * styledText.setStyleRanges(ranges); */ /* The replaceStyleRanges() method */ // Create the array to hold the StyleRanges StyleRange[] ranges = new StyleRange[2]; // Create the first StyleRange, making sure not to overlap. Include the // space. ranges[0] = new StyleRange(0, 3, orange, null); // Create the second StyleRange ranges[1] = new StyleRange(3, 6, blue, null); // Replace only the StyleRanges in the affected area styledText.replaceStyleRanges(0, 9, ranges); }
From source file:org.eclipse.swt.examples.layoutexample.Tab.java
/** * Refreshes the composite and draws all controls * in the layout example./*ww w . ja v a 2s .c om*/ */ void refreshLayoutComposite() { /* Remove children that are already laid out */ children = layoutComposite.getChildren(); for (Control child : children) { child.dispose(); } /* Add all children listed in the table */ TableItem[] items = table.getItems(); children = new Control[items.length]; String[] itemValues = new String[] { LayoutExample.getResourceString("Item", new String[] { "1" }), LayoutExample.getResourceString("Item", new String[] { "2" }), LayoutExample.getResourceString("Item", new String[] { "3" }) }; for (int i = 0; i < items.length; i++) { String control = items[i].getText(1); String controlName = items[i].getText(0); if (control.equals("Button")) { Button button = new Button(layoutComposite, SWT.PUSH); button.setText(controlName); children[i] = button; } else if (control.equals("Canvas")) { Canvas canvas = new Canvas(layoutComposite, SWT.BORDER); children[i] = canvas; } else if (control.equals("Combo")) { Combo combo = new Combo(layoutComposite, SWT.NONE); combo.setItems(itemValues); combo.setText(controlName); children[i] = combo; } else if (control.equals("Composite")) { Composite composite = new Composite(layoutComposite, SWT.BORDER); children[i] = composite; } else if (control.equals("CoolBar")) { CoolBar coolBar = new CoolBar(layoutComposite, SWT.NONE); ToolBar toolBar = new ToolBar(coolBar, SWT.BORDER); ToolItem item = new ToolItem(toolBar, 0); item.setText(LayoutExample.getResourceString("Item", new String[] { "1" })); item = new ToolItem(toolBar, 0); item.setText(LayoutExample.getResourceString("Item", new String[] { "2" })); CoolItem coolItem1 = new CoolItem(coolBar, 0); coolItem1.setControl(toolBar); toolBar = new ToolBar(coolBar, SWT.BORDER); item = new ToolItem(toolBar, 0); item.setText(LayoutExample.getResourceString("Item", new String[] { "3" })); item = new ToolItem(toolBar, 0); item.setText(LayoutExample.getResourceString("Item", new String[] { "4" })); CoolItem coolItem2 = new CoolItem(coolBar, 0); coolItem2.setControl(toolBar); Point size = toolBar.computeSize(SWT.DEFAULT, SWT.DEFAULT); coolItem1.setSize(coolItem1.computeSize(size.x, size.y)); coolItem2.setSize(coolItem2.computeSize(size.x, size.y)); coolBar.setSize(coolBar.computeSize(SWT.DEFAULT, SWT.DEFAULT)); children[i] = coolBar; } else if (control.equals("Group")) { Group group = new Group(layoutComposite, SWT.NONE); group.setText(controlName); children[i] = group; } else if (control.equals("Label")) { Label label = new Label(layoutComposite, SWT.NONE); label.setText(controlName); children[i] = label; } else if (control.equals("Link")) { Link link = new Link(layoutComposite, SWT.NONE); link.setText(controlName); children[i] = link; } else if (control.equals("List")) { org.eclipse.swt.widgets.List list = new org.eclipse.swt.widgets.List(layoutComposite, SWT.BORDER); list.setItems(itemValues); children[i] = list; } else if (control.equals("ProgressBar")) { ProgressBar progress = new ProgressBar(layoutComposite, SWT.NONE); progress.setSelection(50); children[i] = progress; } else if (control.equals("Scale")) { Scale scale = new Scale(layoutComposite, SWT.NONE); children[i] = scale; } else if (control.equals("Slider")) { Slider slider = new Slider(layoutComposite, SWT.NONE); children[i] = slider; } else if (control.equals("StyledText")) { StyledText styledText = new StyledText(layoutComposite, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); styledText.setText(controlName); children[i] = styledText; } else if (control.equals("Table")) { Table table = new Table(layoutComposite, SWT.BORDER); table.setLinesVisible(true); TableItem item1 = new TableItem(table, 0); item1.setText(LayoutExample.getResourceString("Item", new String[] { "1" })); TableItem item2 = new TableItem(table, 0); item2.setText(LayoutExample.getResourceString("Item", new String[] { "2" })); children[i] = table; } else if (control.equals("Text")) { Text text = new Text(layoutComposite, SWT.BORDER); text.setText(controlName); children[i] = text; } else if (control.equals("ToolBar")) { ToolBar toolBar = new ToolBar(layoutComposite, SWT.BORDER); ToolItem item1 = new ToolItem(toolBar, 0); item1.setText(LayoutExample.getResourceString("Item", new String[] { "1" })); ToolItem item2 = new ToolItem(toolBar, 0); item2.setText(LayoutExample.getResourceString("Item", new String[] { "2" })); children[i] = toolBar; } else { Tree tree = new Tree(layoutComposite, SWT.BORDER); TreeItem item1 = new TreeItem(tree, 0); item1.setText(LayoutExample.getResourceString("Item", new String[] { "1" })); TreeItem item2 = new TreeItem(tree, 0); item2.setText(LayoutExample.getResourceString("Item", new String[] { "2" })); children[i] = tree; } } }
From source file:org.eclipse.swt.examples.dnd.DNDExample.java
private Control createWidget(int type, Composite parent, String prefix) { switch (type) { case BUTTON_CHECK: { Button button = new Button(parent, SWT.CHECK); button.setText(prefix + " Check box"); return button; }/*from w w w . j a v a 2 s . co m*/ case BUTTON_TOGGLE: { Button button = new Button(parent, SWT.TOGGLE); button.setText(prefix + " Toggle button"); return button; } case BUTTON_RADIO: { Button button = new Button(parent, SWT.RADIO); button.setText(prefix + " Radio button"); return button; } case STYLED_TEXT: { StyledText text = new StyledText(parent, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL); text.setText(prefix + " Styled Text"); return text; } case TABLE: { Table table = new Table(parent, SWT.BORDER | SWT.MULTI); table.setHeaderVisible(true); TableColumn column0 = new TableColumn(table, SWT.LEFT); column0.setText("Name"); TableColumn column1 = new TableColumn(table, SWT.RIGHT); column1.setText("Value"); TableColumn column2 = new TableColumn(table, SWT.CENTER); column2.setText("Description"); for (int i = 0; i < 10; i++) { TableItem item = new TableItem(table, SWT.NONE); item.setText(0, prefix + " name " + i); item.setText(1, prefix + " value " + i); item.setText(2, prefix + " description " + i); item.setImage(itemImage); } column0.pack(); column1.pack(); column2.pack(); return table; } case TEXT: { Text text = new Text(parent, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL); text.setText(prefix + " Text"); return text; } case TREE: { Tree tree = new Tree(parent, SWT.BORDER | SWT.MULTI); tree.setHeaderVisible(true); TreeColumn column0 = new TreeColumn(tree, SWT.LEFT); column0.setText("Name"); TreeColumn column1 = new TreeColumn(tree, SWT.RIGHT); column1.setText("Value"); TreeColumn column2 = new TreeColumn(tree, SWT.CENTER); column2.setText("Description"); for (int i = 0; i < 3; i++) { TreeItem item = new TreeItem(tree, SWT.NONE); item.setText(0, prefix + " name " + i); item.setText(1, prefix + " value " + i); item.setText(2, prefix + " description " + i); item.setImage(itemImage); for (int j = 0; j < 3; j++) { TreeItem subItem = new TreeItem(item, SWT.NONE); subItem.setText(0, prefix + " name " + i + " " + j); subItem.setText(1, prefix + " value " + i + " " + j); subItem.setText(2, prefix + " description " + i + " " + j); subItem.setImage(itemImage); for (int k = 0; k < 3; k++) { TreeItem subsubItem = new TreeItem(subItem, SWT.NONE); subsubItem.setText(0, prefix + " name " + i + " " + j + " " + k); subsubItem.setText(1, prefix + " value " + i + " " + j + " " + k); subsubItem.setText(2, prefix + " description " + i + " " + j + " " + k); subsubItem.setImage(itemImage); } } } column0.pack(); column1.pack(); column2.pack(); return tree; } case CANVAS: { Canvas canvas = new Canvas(parent, SWT.BORDER); canvas.setData("STRINGS", new String[] { prefix + " Canvas widget" }); canvas.addPaintListener(e -> { Canvas c = (Canvas) e.widget; Image image = (Image) c.getData("IMAGE"); if (image != null) { e.gc.drawImage(image, 5, 5); } else { String[] strings = (String[]) c.getData("STRINGS"); if (strings != null) { FontMetrics metrics = e.gc.getFontMetrics(); int height = metrics.getHeight(); int y = 5; for (String string : strings) { e.gc.drawString(string, 5, y); y += height + 5; } } } }); return canvas; } case LABEL: { Label label = new Label(parent, SWT.BORDER); label.setText(prefix + " Label"); return label; } case LIST: { List list = new List(parent, SWT.BORDER | SWT.MULTI); list.setItems(prefix + " Item a", prefix + " Item b", prefix + " Item c", prefix + " Item d"); return list; } case COMBO: { Combo combo = new Combo(parent, SWT.BORDER); combo.setItems("Item a", "Item b", "Item c", "Item d"); return combo; } default: throw new SWTError(SWT.ERROR_NOT_IMPLEMENTED); } }
From source file:LayoutExample.java
/** * Refreshes the composite and draws all controls in the layout example. */// w w w.j av a 2 s . c om void refreshLayoutComposite() { /* Remove children that are already laid out */ children = layoutComposite.getChildren(); for (int i = 0; i < children.length; i++) { children[i].dispose(); } /* Add all children listed in the table */ TableItem[] items = table.getItems(); children = new Control[items.length]; String[] itemValues = new String[] { LayoutExample.getResourceString("Item", new String[] { "1" }), LayoutExample.getResourceString("Item", new String[] { "2" }), LayoutExample.getResourceString("Item", new String[] { "3" }) }; for (int i = 0; i < items.length; i++) { String control = items[i].getText(1); if (control.equals("Button")) { Button button = new Button(layoutComposite, SWT.PUSH); button.setText(LayoutExample.getResourceString("Button_Index", new String[] { new Integer(i).toString() })); children[i] = button; } else if (control.equals("Canvas")) { Canvas canvas = new Canvas(layoutComposite, SWT.BORDER); children[i] = canvas; } else if (control.equals("Combo")) { Combo combo = new Combo(layoutComposite, SWT.NONE); combo.setItems(itemValues); combo.setText( LayoutExample.getResourceString("Combo_Index", new String[] { new Integer(i).toString() })); children[i] = combo; } else if (control.equals("Composite")) { Composite composite = new Composite(layoutComposite, SWT.BORDER); children[i] = composite; } else if (control.equals("CoolBar")) { CoolBar coolBar = new CoolBar(layoutComposite, SWT.NONE); ToolBar toolBar = new ToolBar(coolBar, SWT.BORDER); ToolItem item = new ToolItem(toolBar, 0); item.setText(LayoutExample.getResourceString("Item", new String[] { "1" })); item = new ToolItem(toolBar, 0); item.setText(LayoutExample.getResourceString("Item", new String[] { "2" })); CoolItem coolItem1 = new CoolItem(coolBar, 0); coolItem1.setControl(toolBar); toolBar = new ToolBar(coolBar, SWT.BORDER); item = new ToolItem(toolBar, 0); item.setText(LayoutExample.getResourceString("Item", new String[] { "3" })); item = new ToolItem(toolBar, 0); item.setText(LayoutExample.getResourceString("Item", new String[] { "4" })); CoolItem coolItem2 = new CoolItem(coolBar, 0); coolItem2.setControl(toolBar); Point size = toolBar.computeSize(SWT.DEFAULT, SWT.DEFAULT); coolItem1.setSize(coolItem1.computeSize(size.x, size.y)); coolItem2.setSize(coolItem2.computeSize(size.x, size.y)); coolBar.setSize(coolBar.computeSize(SWT.DEFAULT, SWT.DEFAULT)); children[i] = coolBar; } else if (control.equals("Group")) { Group group = new Group(layoutComposite, SWT.NONE); group.setText( LayoutExample.getResourceString("Group_Index", new String[] { new Integer(i).toString() })); children[i] = group; } else if (control.equals("Label")) { Label label = new Label(layoutComposite, SWT.NONE); label.setText( LayoutExample.getResourceString("Label_Index", new String[] { new Integer(i).toString() })); children[i] = label; } else if (control.equals("List")) { List list = new List(layoutComposite, SWT.BORDER); list.setItems(itemValues); children[i] = list; } else if (control.equals("ProgressBar")) { ProgressBar progress = new ProgressBar(layoutComposite, SWT.NONE); progress.setSelection(50); children[i] = progress; } else if (control.equals("Scale")) { Scale scale = new Scale(layoutComposite, SWT.NONE); children[i] = scale; } else if (control.equals("Slider")) { Slider slider = new Slider(layoutComposite, SWT.NONE); children[i] = slider; } else if (control.equals("StyledText")) { StyledText styledText = new StyledText(layoutComposite, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); styledText.setText(LayoutExample.getResourceString("StyledText_Index", new String[] { new Integer(i).toString() })); children[i] = styledText; } else if (control.equals("Table")) { Table table = new Table(layoutComposite, SWT.BORDER); table.setLinesVisible(true); TableItem item1 = new TableItem(table, 0); item1.setText(LayoutExample.getResourceString("Item", new String[] { "1" })); TableItem item2 = new TableItem(table, 0); item2.setText(LayoutExample.getResourceString("Item", new String[] { "2" })); children[i] = table; } else if (control.equals("Text")) { Text text = new Text(layoutComposite, SWT.BORDER); text.setText( LayoutExample.getResourceString("Text_Index", new String[] { new Integer(i).toString() })); children[i] = text; } else if (control.equals("ToolBar")) { ToolBar toolBar = new ToolBar(layoutComposite, SWT.BORDER); ToolItem item1 = new ToolItem(toolBar, 0); item1.setText(LayoutExample.getResourceString("Item", new String[] { "1" })); ToolItem item2 = new ToolItem(toolBar, 0); item2.setText(LayoutExample.getResourceString("Item", new String[] { "2" })); children[i] = toolBar; } else { Tree tree = new Tree(layoutComposite, SWT.BORDER); TreeItem item1 = new TreeItem(tree, 0); item1.setText(LayoutExample.getResourceString("Item", new String[] { "1" })); TreeItem item2 = new TreeItem(tree, 0); item2.setText(LayoutExample.getResourceString("Item", new String[] { "2" })); children[i] = tree; } } }
From source file:LayoutExample.java
/** * Creates the "control" widget children. Subclasses override this method to * augment the standard controls created. */// w w w . j a v a2s . c o m void createControlWidgets() { createChildGroup(); code = new Button(controlGroup, SWT.PUSH); code.setText(LayoutExample.getResourceString("Code")); GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_CENTER | GridData.GRAB_HORIZONTAL); gridData.horizontalSpan = 2; code.setLayoutData(gridData); code.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { final Shell shell = new Shell(); shell.setText(LayoutExample.getResourceString("Generated_Code")); shell.setLayout(new FillLayout()); final StyledText text = new StyledText(shell, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL); String layoutCode = generateCode().toString(); if (layoutCode.length() == 0) return; text.setText(layoutCode); Menu bar = new Menu(shell, SWT.BAR); shell.setMenuBar(bar); MenuItem editItem = new MenuItem(bar, SWT.CASCADE); editItem.setText(LayoutExample.getResourceString("Edit")); Menu menu = new Menu(bar); MenuItem select = new MenuItem(menu, SWT.PUSH); select.setText(LayoutExample.getResourceString("Select_All")); select.setAccelerator(SWT.MOD1 + 'A'); select.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { text.selectAll(); } }); MenuItem copy = new MenuItem(menu, SWT.PUSH); copy.setText(LayoutExample.getResourceString("Copy")); copy.setAccelerator(SWT.MOD1 + 'C'); copy.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { text.copy(); } }); MenuItem exit = new MenuItem(menu, SWT.PUSH); exit.setText(LayoutExample.getResourceString("Exit")); exit.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { shell.close(); } }); editItem.setMenu(menu); shell.pack(); shell.setSize(400, 500); shell.open(); Display display = shell.getDisplay(); while (!shell.isDisposed()) if (!display.readAndDispatch()) display.sleep(); } }); }