List of usage examples for org.eclipse.swt.custom StyledText getCharCount
public int getCharCount()
From source file:StyledTextModifyListener.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); final StyledText styledText = new StyledText(shell, SWT.V_SCROLL | SWT.BORDER); styledText.setText("12345"); styledText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent event) { System.out.println("Character Count: " + styledText.getCharCount()); }// w w w. j av a2 s . c om }); styledText.setBounds(10, 10, 100, 100); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:StyledTextStatistics.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); StyledText styledText = new StyledText(shell, SWT.V_SCROLL | SWT.BORDER); styledText.setText("12345"); System.out.println("Caret Offset: " + styledText.getCaretOffset()); System.out.println("Total Lines of Text: " + styledText.getLineCount()); System.out.println("Total Characters: " + styledText.getCharCount()); System.out.println("Current Line: " + (styledText.getLineAtOffset(styledText.getCaretOffset()) + 1)); styledText.setBounds(10, 10, 100, 100); shell.open();//from w w w.j av a 2s .co m while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet316.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 316"); shell.setLayout(new FillLayout()); StyledText text = new StyledText(shell, SWT.V_SCROLL | SWT.H_SCROLL); text.setText("StyledText with margins."); Font font = new Font(display, "Tahoma", 14, SWT.ITALIC); text.setText(/*ww w . ja v a2 s . c om*/ "\"If you go down to the woods today\nYou'd better not go alone\nIt's lovely down in the woods today\nBut safer to stay at home\""); StyleRange italic = new StyleRange(); italic.font = font; text.setStyleRanges(new int[] { 0, text.getCharCount() }, new StyleRange[] { italic }); text.setMargins(30, 30, 30, 30); Color color = new Color(display, 138, 226, 255); text.setMarginColor(color); shell.setSize(500, 300); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } font.dispose(); color.dispose(); display.dispose(); }