List of usage examples for org.eclipse.swt.widgets Button setText
public void setText(String text)
From source file:org.eclipse.swt.snippets.Snippet322.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 322"); shell.setBounds(10, 10, 300, 300);//from ww w.j av a 2s. c om final ScrolledComposite sc = new ScrolledComposite(shell, SWT.VERTICAL); sc.setBounds(10, 10, 280, 200); final int clientWidth = sc.getClientArea().width; final Tree tree = new Tree(sc, SWT.NONE); for (int i = 0; i < 99; i++) { TreeItem item = new TreeItem(tree, SWT.NONE); item.setText("item " + i); new TreeItem(item, SWT.NONE).setText("child"); } sc.setContent(tree); int prefHeight = tree.computeSize(SWT.DEFAULT, SWT.DEFAULT).y; tree.setSize(clientWidth, prefHeight); /* * The following listener ensures that the Tree is always large * enough to not need to show its own vertical scrollbar. */ tree.addTreeListener(new TreeListener() { @Override public void treeExpanded(TreeEvent e) { int prefHeight = tree.computeSize(SWT.DEFAULT, SWT.DEFAULT).y; tree.setSize(clientWidth, prefHeight); } @Override public void treeCollapsed(TreeEvent e) { int prefHeight = tree.computeSize(SWT.DEFAULT, SWT.DEFAULT).y; tree.setSize(clientWidth, prefHeight); } }); /* * The following listener ensures that a newly-selected item * in the Tree is always visible. */ tree.addSelectionListener(widgetSelectedAdapter(e -> { TreeItem[] selectedItems = tree.getSelection(); if (selectedItems.length > 0) { Rectangle itemRect = selectedItems[0].getBounds(); Rectangle area = sc.getClientArea(); Point origin = sc.getOrigin(); if (itemRect.x < origin.x || itemRect.y < origin.y || itemRect.x + itemRect.width > origin.x + area.width || itemRect.y + itemRect.height > origin.y + area.height) { sc.setOrigin(itemRect.x, itemRect.y); } } })); /* * The following listener scrolls the Tree one item at a time * in response to MouseWheel events. */ tree.addListener(SWT.MouseWheel, event -> { Point origin = sc.getOrigin(); if (event.count < 0) { origin.y = Math.min(origin.y + tree.getItemHeight(), tree.getSize().y); } else { origin.y = Math.max(origin.y - tree.getItemHeight(), 0); } sc.setOrigin(origin); }); Button disableButton = new Button(shell, SWT.PUSH); disableButton.setBounds(10, 220, 120, 30); disableButton.setText("Disable"); disableButton.addListener(SWT.Selection, event -> tree.setEnabled(false)); Button enableButton = new Button(shell, SWT.PUSH); enableButton.setBounds(140, 220, 120, 30); enableButton.setText("Enable"); enableButton.addListener(SWT.Selection, event -> tree.setEnabled(true)); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet315.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 315"); shell.setLayout(new GridLayout()); final Button button = new Button(shell, SWT.CHECK); button.setLayoutData(//from w ww .j a v a 2 s .co m new GridData(GridData.GRAB_VERTICAL | GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_CENTER)); button.setText("Tri-state"); /* Make the button toggle between three states */ button.addListener(SWT.Selection, e -> { if (button.getSelection()) { if (!button.getGrayed()) { button.setGrayed(true); } } else { if (button.getGrayed()) { button.setGrayed(false); button.setSelection(true); } } }); /* Read the tri-state button (application code) */ button.addListener(SWT.Selection, e -> { if (button.getGrayed()) { System.out.println("Grayed"); } else { if (button.getSelection()) { System.out.println("Selected"); } else { System.out.println("Not selected"); } } }); shell.setSize(300, 300); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet341.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FormLayout()); GLData data = new GLData(); data.doubleBuffer = true;/*from w w w. j a v a 2 s .c om*/ final GLCanvas canvas = new GLCanvas(shell, SWT.NONE, data); canvas.setCurrent(); GL.createCapabilities(); canvas.addListener(SWT.Resize, event -> { Rectangle bounds = canvas.getBounds(); float fAspect = (float) bounds.width / (float) bounds.height; canvas.setCurrent(); GL.createCapabilities(); GL11.glViewport(0, 0, bounds.width, bounds.height); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); float near = 0.5f; float bottom = -near * (float) Math.tan(45.f / 2); float left = fAspect * bottom; GL11.glFrustum(left, -left, bottom, -bottom, near, 400.f); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glLoadIdentity(); }); GL11.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); GL11.glColor3f(1.0f, 0.0f, 0.0f); GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST); GL11.glClearDepth(1.0); GL11.glLineWidth(2); GL11.glEnable(GL11.GL_DEPTH_TEST); Button button = new Button(shell, SWT.PUSH); button.setText("Capture"); button.addListener(SWT.Selection, event -> capture(canvas)); FormData formData = new FormData(640, 480); formData.top = new FormAttachment(0, 0); formData.left = new FormAttachment(0, 0); formData.bottom = new FormAttachment(button, 0); formData.right = new FormAttachment(100, 0); canvas.setLayoutData(formData); formData = new FormData(); formData.left = new FormAttachment(0, 0); formData.bottom = new FormAttachment(100, 0); formData.right = new FormAttachment(100, 0); button.setLayoutData(formData); shell.pack(); shell.open(); display.asyncExec(new Runnable() { int rot = 0; @Override public void run() { if (!canvas.isDisposed()) { canvas.setCurrent(); GL.createCapabilities(); GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); GL11.glClearColor(.3f, .5f, .8f, 1.0f); GL11.glLoadIdentity(); GL11.glTranslatef(0.0f, 0.0f, -10.0f); float frot = rot; GL11.glRotatef(0.15f * rot, 2.0f * frot, 10.0f * frot, 1.0f); GL11.glRotatef(0.3f * rot, 3.0f * frot, 1.0f * frot, 1.0f); rot++; GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE); GL11.glColor3f(0.9f, 0.9f, 0.9f); drawTorus(1, 1.9f + ((float) Math.sin((0.004f * frot))), 15, 15); canvas.swapBuffers(); display.asyncExec(this); } } }); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet186.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 186"); shell.setLayout(new GridLayout(2, false)); final Text text = new Text(shell, SWT.BORDER); text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); Button go = new Button(shell, SWT.PUSH); go.setText("Go"); OleFrame oleFrame = new OleFrame(shell, SWT.NONE); oleFrame.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); OleControlSite controlSite;/*from w ww.j av a 2 s.c o m*/ OleAutomation automation; try { controlSite = new OleControlSite(oleFrame, SWT.NONE, "Shell.Explorer"); automation = new OleAutomation(controlSite); controlSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE); } catch (SWTException ex) { System.out.println("Unable to open activeX control"); display.dispose(); return; } final OleAutomation auto = automation; go.addListener(SWT.Selection, new Listener() { @Override public void handleEvent(Event e) { String url = text.getText(); int[] rgdispid = auto.getIDsOfNames(new String[] { "Navigate", "URL" }); int dispIdMember = rgdispid[0]; Variant[] rgvarg = new Variant[1]; rgvarg[0] = new Variant(url); int[] rgdispidNamedArgs = new int[1]; rgdispidNamedArgs[0] = rgdispid[1]; auto.invoke(dispIdMember, rgvarg, rgdispidNamedArgs); } }); // Read PostData whenever we navigate to a site that uses it int BeforeNavigate2 = 0xfa; controlSite.addEventListener(BeforeNavigate2, new OleListener() { @Override public void handleEvent(OleEvent event) { Variant url = event.arguments[1]; Variant postData = event.arguments[4]; if (postData != null) { System.out.println("PostData = " + readSafeArray(postData) + ", URL = " + url.getString()); } } }); // Navigate to this web site which uses post data to fill in the text field // and put the string "hello world" into the text box text.setText("file://" + Snippet186.class.getResource("Snippet186.html").getFile()); int[] rgdispid = automation.getIDsOfNames(new String[] { "Navigate", "URL", "PostData" }); int dispIdMember = rgdispid[0]; Variant[] rgvarg = new Variant[2]; rgvarg[0] = new Variant(text.getText()); rgvarg[1] = writeSafeArray("hello world"); int[] rgdispidNamedArgs = new int[2]; rgdispidNamedArgs[0] = rgdispid[1]; rgdispidNamedArgs[1] = rgdispid[2]; automation.invoke(dispIdMember, rgvarg, rgdispidNamedArgs); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:Snippet186.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new GridLayout(2, false)); final Text text = new Text(shell, SWT.BORDER); text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); Button go = new Button(shell, SWT.PUSH); go.setText("Go"); OleFrame oleFrame = new OleFrame(shell, SWT.NONE); oleFrame.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); OleControlSite controlSite;/*from w w w.j ava 2 s . c o m*/ OleAutomation automation; try { controlSite = new OleControlSite(oleFrame, SWT.NONE, "Shell.Explorer"); automation = new OleAutomation(controlSite); controlSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE); } catch (SWTException ex) { return; } final OleAutomation auto = automation; go.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { String url = text.getText(); int[] rgdispid = auto.getIDsOfNames(new String[] { "Navigate", "URL" }); int dispIdMember = rgdispid[0]; Variant[] rgvarg = new Variant[1]; rgvarg[0] = new Variant(url); int[] rgdispidNamedArgs = new int[1]; rgdispidNamedArgs[0] = rgdispid[1]; auto.invoke(dispIdMember, rgvarg, rgdispidNamedArgs); } }); // Read PostData whenever we navigate to a site that uses it int BeforeNavigate2 = 0xfa; controlSite.addEventListener(BeforeNavigate2, new OleListener() { public void handleEvent(OleEvent event) { Variant url = event.arguments[1]; Variant postData = event.arguments[4]; if (postData != null) { System.out.println("PostData = " + readSafeArray(postData) + ", URL = " + url.getString()); } } }); // Navigate to this web site which uses post data to fill in the text // field // and put the string "hello world" into the text box text.setText("file://" + Snippet186.class.getResource("Snippet186.html").getFile()); int[] rgdispid = automation.getIDsOfNames(new String[] { "Navigate", "URL", "PostData" }); int dispIdMember = rgdispid[0]; Variant[] rgvarg = new Variant[2]; rgvarg[0] = new Variant(text.getText()); rgvarg[1] = writeSafeArray("hello world"); int[] rgdispidNamedArgs = new int[2]; rgdispidNamedArgs[0] = rgdispid[1]; rgdispidNamedArgs[1] = rgdispid[2]; automation.invoke(dispIdMember, rgvarg, rgdispidNamedArgs); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet338.java
public static void main(String[] args) { Display display = new Display(); Shell parentShell = new Shell(display); parentShell.setText("Snippet 338"); parentShell.setBounds(10, 10, 100, 100); parentShell.open();// w ww. j av a 2 s .c o m Shell childShell = new Shell(parentShell); childShell.setLayout(new GridLayout()); TabFolder folder = new TabFolder(childShell, SWT.NONE); folder.setLayout(new FillLayout()); TabItem tab1 = new TabItem(folder, SWT.NONE); tab1.setText("Tab &1"); new TabItem(folder, SWT.NONE).setText("Tab &2"); Composite composite = new Composite(folder, SWT.NONE); composite.setLayout(new GridLayout()); tab1.setControl(composite); Text text1 = new Text(composite, SWT.SINGLE); /* canvas represents a custom control */ final Canvas canvas = new Canvas(composite, SWT.BORDER); canvas.setLayoutData(new GridData(300, 200)); canvas.addListener(SWT.Paint, event -> { if (canvas.isFocusControl()) { event.gc.drawText( "focus is here, custom traverse keys:\n\tN: Tab next\n\tP: Tab previous\n\tR: Return\n\tE: Esc\n\tT: Tab Folder next page", 0, 0); } else { event.gc.drawString("focus is not in this control", 0, 0); } }); canvas.addListener(SWT.KeyDown, event -> { int traversal = SWT.NONE; switch (event.keyCode) { case 'n': traversal = SWT.TRAVERSE_TAB_NEXT; break; case 'p': traversal = SWT.TRAVERSE_TAB_PREVIOUS; break; case 'r': traversal = SWT.TRAVERSE_RETURN; break; case 'e': traversal = SWT.TRAVERSE_ESCAPE; break; case 't': traversal = SWT.TRAVERSE_PAGE_NEXT; break; } if (traversal != SWT.NONE) { event.doit = true; /* this will be the Traverse event's initial doit value */ canvas.traverse(traversal, event); } }); canvas.addFocusListener(focusLostAdapter(e -> canvas.redraw())); canvas.addFocusListener(focusGainedAdapter(e -> canvas.redraw())); Text text2 = new Text(composite, SWT.SINGLE); Button button = new Button(childShell, SWT.PUSH); button.setText("Default &Button"); button.addListener(SWT.Selection, event -> System.out.println("Default button selected")); childShell.setDefaultButton(button); Listener printTraverseListener = event -> { StringBuilder buffer = new StringBuilder("Traverse "); buffer.append(event.widget); buffer.append(" type="); switch (event.detail) { case SWT.TRAVERSE_ARROW_NEXT: buffer.append("TRAVERSE_ARROW_NEXT"); break; case SWT.TRAVERSE_ARROW_PREVIOUS: buffer.append("TRAVERSE_ARROW_NEXT"); break; case SWT.TRAVERSE_ESCAPE: buffer.append("TRAVERSE_ESCAPE"); break; case SWT.TRAVERSE_MNEMONIC: buffer.append("TRAVERSE_MNEMONIC"); break; case SWT.TRAVERSE_PAGE_NEXT: buffer.append("TRAVERSE_PAGE_NEXT"); break; case SWT.TRAVERSE_PAGE_PREVIOUS: buffer.append("TRAVERSE_PAGE_PREVIOUS"); break; case SWT.TRAVERSE_RETURN: buffer.append("TRAVERSE_RETURN"); break; case SWT.TRAVERSE_TAB_NEXT: buffer.append("TRAVERSE_TAB_NEXT"); break; case SWT.TRAVERSE_TAB_PREVIOUS: buffer.append("TRAVERSE_TAB_PREVIOUS"); break; } buffer.append(" doit=" + event.doit); buffer.append(" keycode=" + event.keyCode); buffer.append(" char=" + event.character); buffer.append(" stateMask=" + event.stateMask); System.out.println(buffer.toString()); }; childShell.addListener(SWT.Traverse, printTraverseListener); folder.addListener(SWT.Traverse, printTraverseListener); composite.addListener(SWT.Traverse, printTraverseListener); canvas.addListener(SWT.Traverse, printTraverseListener); button.addListener(SWT.Traverse, printTraverseListener); text1.addListener(SWT.Traverse, printTraverseListener); text2.addListener(SWT.Traverse, printTraverseListener); childShell.pack(); childShell.open(); text1.setFocus(); while (!parentShell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.examples.accessibility.AccessibleActionExample.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); shell.setText("Accessible Action Example"); Button button = new Button(shell, SWT.PUSH); button.setText("Button"); final Canvas customButton = new Canvas(shell, SWT.NONE) { @Override//www . j av a 2s . co m public Point computeSize(int wHint, int hHint, boolean changed) { GC gc = new GC(this); Point point = gc.stringExtent(buttonText); gc.dispose(); point.x += MARGIN; point.y += MARGIN; return point; } }; customButton.addPaintListener(e -> { Rectangle clientArea = customButton.getClientArea(); Point stringExtent = e.gc.stringExtent(buttonText); int x = clientArea.x + (clientArea.width - stringExtent.x) / 2; int y = clientArea.y + (clientArea.height - stringExtent.y) / 2; e.gc.drawString(buttonText, x, y); }); customButton.addMouseListener(MouseListener.mouseDownAdapter(e -> { int actionIndex = (e.button == 1) ? 0 : 1; customButtonAction(actionIndex); })); customButton.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { int modifierKeys = e.stateMask & SWT.MODIFIER_MASK; if (modifierKeys == SWT.CTRL || modifierKeys == 0) { if (e.character == '1') customButtonAction(0); else if (e.character == '2') customButtonAction(1); } } }); Accessible accessible = customButton.getAccessible(); accessible.addAccessibleListener(new AccessibleAdapter() { @Override public void getName(AccessibleEvent e) { e.result = buttonText; } @Override public void getKeyboardShortcut(AccessibleEvent e) { e.result = "CTRL+1"; // default action is 'action 1' } }); accessible.addAccessibleControlListener(new AccessibleControlAdapter() { @Override public void getRole(AccessibleControlEvent e) { e.detail = ACC.ROLE_PUSHBUTTON; } }); accessible.addAccessibleActionListener(new AccessibleActionAdapter() { @Override public void getActionCount(AccessibleActionEvent e) { e.count = 2; } @Override public void getName(AccessibleActionEvent e) { if (0 <= e.index && e.index <= 1) { if (e.localized) { e.result = AccessibleActionExample.getResourceString("action" + e.index); } else { e.result = "Action" + e.index; //$NON-NLS-1$ } } } @Override public void getDescription(AccessibleActionEvent e) { if (0 <= e.index && e.index <= 1) { e.result = AccessibleActionExample.getResourceString("action" + e.index + "description"); } } @Override public void doAction(AccessibleActionEvent e) { if (0 <= e.index && e.index <= 1) { customButtonAction(e.index); e.result = ACC.OK; } } @Override public void getKeyBinding(AccessibleActionEvent e) { switch (e.index) { case 0: e.result = "1;CTRL+1"; break; case 1: e.result = "2;CTRL+2"; break; default: e.result = null; } } }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet361.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Snippet 361"); shell.setText("Translate and Rotate an AWT Image in an SWT GUI"); shell.setLayout(new GridLayout(8, false)); Button fileButton = new Button(shell, SWT.PUSH); fileButton.setText("&Open Image File"); fileButton.addSelectionListener(widgetSelectedAdapter(e -> { String filename = new FileDialog(shell).open(); if (filename != null) { image = Toolkit.getDefaultToolkit().getImage(filename); canvas.repaint();/*from w ww.jav a 2 s . co m*/ } })); new Label(shell, SWT.NONE).setText("Translate &X by:"); final Combo translateXCombo = new Combo(shell, SWT.NONE); translateXCombo.setItems("0", "image width", "image height", "100", "200"); translateXCombo.select(0); translateXCombo.addModifyListener(e -> { translateX = numericValue(translateXCombo); canvas.repaint(); }); new Label(shell, SWT.NONE).setText("Translate &Y by:"); final Combo translateYCombo = new Combo(shell, SWT.NONE); translateYCombo.setItems("0", "image width", "image height", "100", "200"); translateYCombo.select(0); translateYCombo.addModifyListener(e -> { translateY = numericValue(translateYCombo); canvas.repaint(); }); new Label(shell, SWT.NONE).setText("&Rotate by:"); final Combo rotateCombo = new Combo(shell, SWT.NONE); rotateCombo.setItems("0", "Pi", "Pi/2", "Pi/4", "Pi/8"); rotateCombo.select(0); rotateCombo.addModifyListener(e -> { rotate = numericValue(rotateCombo); canvas.repaint(); }); Button printButton = new Button(shell, SWT.PUSH); printButton.setText("&Print Image"); printButton.addSelectionListener(widgetSelectedAdapter(e -> { performPrintAction(display, shell); })); composite = new Composite(shell, SWT.EMBEDDED | SWT.BORDER); GridData data = new GridData(SWT.FILL, SWT.FILL, true, true, 8, 1); data.widthHint = 640; data.heightHint = 480; composite.setLayoutData(data); Frame frame = SWT_AWT.new_Frame(composite); canvas = new Canvas() { @Override public void paint(Graphics g) { if (image != null) { g.setColor(Color.WHITE); g.fillRect(0, 0, canvas.getWidth(), canvas.getHeight()); /* Use Java2D here to modify the image as desired. */ Graphics2D g2d = (Graphics2D) g; AffineTransform t = new AffineTransform(); t.translate(translateX, translateY); t.rotate(rotate); g2d.setTransform(t); /*------------*/ g.drawImage(image, 0, 0, this); } } }; frame.add(canvas); composite.getAccessible().addAccessibleListener(new AccessibleAdapter() { @Override public void getName(AccessibleEvent e) { e.result = "Image drawn in AWT Canvas"; } }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:KalendarDialog.java
/** * @param args//from w w w . jav a2 s . co m */ public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setText(""); FillLayout fl = new FillLayout(); shell.setLayout(fl); Button open = new Button(shell, SWT.PUSH); open.setText("open"); open.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { KalendarDialog cd = new KalendarDialog(shell); System.out.println(cd.open()); } }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } }
From source file:org.eclipse.swt.snippets.Snippet375.java
public static void main(String[] args) throws Exception { final Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Snippet 375"); shell.setLayout(new GridLayout(1, false)); final StringBuilder sb = new StringBuilder(); final Random random = new Random(2546); for (int i = 0; i < 200; i++) { sb.append("Very very long text about ").append(random.nextInt(2000)).append("\t"); if (i % 10 == 0) { sb.append("\n"); }//ww w. j a v a 2 s.c o m } // H SCROLL final Label lbl1 = new Label(shell, SWT.NONE); lbl1.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, true, false)); lbl1.setText("Horizontal Scroll"); final StyledText txt1 = new StyledText(shell, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL); txt1.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true)); txt1.setText(sb.toString()); txt1.setMouseNavigatorEnabled(true); // V_SCROLL final Label lbl2 = new Label(shell, SWT.NONE); lbl2.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, true, false)); lbl2.setText("Vertical Scroll"); final StyledText txt2 = new StyledText(shell, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL); txt2.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true)); txt2.setText(sb.toString()); txt2.setMouseNavigatorEnabled(true); // H SCROLL & V_SCROLL final Label lbl3 = new Label(shell, SWT.NONE); lbl3.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, true, false)); lbl3.setText("Horizontal and Vertical Scroll"); final StyledText txt3 = new StyledText(shell, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); txt3.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true)); txt3.setText(sb.toString()); txt3.setMouseNavigatorEnabled(true); final Button enableDisableButton = new Button(shell, SWT.PUSH); enableDisableButton.setLayoutData(new GridData(GridData.END, GridData.FILL, true, false)); enableDisableButton.setText("Disable Mouse Navigation"); enableDisableButton.addListener(SWT.Selection, e -> { if (txt3.getMouseNavigatorEnabled()) { enableDisableButton.setText("Enable Mouse Navigation"); } else { enableDisableButton.setText("Disable Mouse Navigation"); } txt3.setMouseNavigatorEnabled(!txt3.getMouseNavigatorEnabled()); }); // Disabled Scroll at start final Label lbl4 = new Label(shell, SWT.NONE); lbl4.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, true, false)); lbl4.setText("No scroll at start"); final StyledText txt4 = new StyledText(shell, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); final GridData gd = new GridData(GridData.FILL, GridData.FILL, true, true); gd.minimumHeight = 100; txt4.setLayoutData(gd); txt4.setText("Disabled scroll"); txt4.setMouseNavigatorEnabled(true); // Disabled Scroll final Label lbl5 = new Label(shell, SWT.NONE); lbl5.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, true, false)); lbl5.setText("No scroll"); final StyledText txt5 = new StyledText(shell, SWT.MULTI | SWT.BORDER); final GridData gd5 = new GridData(GridData.FILL, GridData.FILL, true, true); gd5.minimumHeight = 100; txt5.setLayoutData(gd5); txt5.setText("No scroll"); txt5.setMouseNavigatorEnabled(true); shell.setSize(800, 600); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }