List of usage examples for org.eclipse.swt.custom StyledText setLayoutData
public void setLayoutData(Object layoutData)
From source file:StyledTextListenerVerify.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setLayout(new GridLayout()); StyledText styledText = new StyledText(shell, SWT.WRAP | SWT.BORDER); styledText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); styledText.setText("text"); // use a verify listener to keep the offsets up to date styledText.addVerifyListener(new VerifyListener() { public void verifyText(VerifyEvent e) { System.out.println(e.start); System.out.println(e.start); System.out.println(e.text.length()); }/*from w w w . j a v a2 s . c o m*/ }); shell.setSize(400, 400); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
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"); }/* w w w.j a va 2s .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(); }
From source file:org.eclipse.swt.snippets.Snippet325.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 325"); shell.setLayout(new GridLayout()); shell.setText("StyledText: Variable tab stops"); Ruler ruler = new Ruler(shell, SWT.NONE); GridData data = new GridData(); data.heightHint = 10;/* www. j a va 2 s . c o m*/ data.horizontalAlignment = SWT.FILL; ruler.setLayoutData(data); ruler.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND)); StyledText styledText = new StyledText(shell, SWT.FULL_SELECTION | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); styledText.setText( "0\t1\t2\t3\t4\nDrag\tthe\ttab\tmarks\ton\ttop\tto\tchange\tthe\tposition\tof\tthe\ttab\tstops"); styledText.setTabStops(new int[] { 30, 70, 90, 140 }); styledText.setLayoutData(new GridData(GridData.FILL_BOTH)); ruler.setEditor(styledText); shell.setSize(800, 400); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet328.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 328"); shell.setLayout(new GridLayout()); shell.setText("StyledText: Variable tab stops"); Ruler ruler = new Ruler(shell, SWT.NONE); GridData data = new GridData(); data.heightHint = 10;//from ww w. jav a2s. c om data.horizontalAlignment = SWT.FILL; ruler.setLayoutData(data); ruler.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND)); StyledText styledText = new StyledText(shell, SWT.FULL_SELECTION | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); styledText.setText( "0\t1\t2\t3\t4\nDrag\tthe\ttab\tmarks\ton\ttop\tto\tchange\tthe\tposition\tof\tthe\ttab\tstops"); styledText.setTabStops(new int[] { 30, 70, 90, 140 }); styledText.setLineTabStops(0, 1, new int[] { 10, 60, 80 }); styledText.setLineTabStops(1, 1, new int[] { 40, 70, 100, 150 }); styledText.setLayoutData(new GridData(GridData.FILL_BOTH)); ruler.setEditor(styledText); shell.setSize(800, 400); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }