Results 1 to 1 of 1
Thread: StyleRange Demonstration
-
StyleRange Demonstration
Java Code:import org.eclipse.swt.SWT; import org.eclipse.swt.custom.*; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.layout.*; import org.eclipse.swt.widgets.*; /** * This class demonstrates StyleRanges */ public class StyleRangeTest { private Color orange; private Color blue; /** * Runs the application */ public void run() { Display display = new Display(); Shell shell = new Shell(display); // Create colors for style ranges orange = new Color(display, 255, 127, 0); blue = display.getSystemColor(SWT.COLOR_BLUE); createContents(shell); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } // We created orange, but not blue orange.dispose(); display.dispose(); } /** * Creates the main window contents * * @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); } /** * The application entry point * * @param args the command line arguments */ public static void main(String[] args) { new StyleRangeTest().run(); } }"The sole cause of mans unhappiness is that he does not know how to stay quietly in his room." - Blaise Pascal
Similar Threads
-
TableTree Demonstration
By Java Tip in forum SWTReplies: 0Last Post: 07-07-2008, 04:57 PM -
TreeViewer Demonstration
By Java Tip in forum SWTReplies: 0Last Post: 07-07-2008, 04:54 PM -
TreeCellRenderer Demonstration
By Java Tip in forum javax.swingReplies: 0Last Post: 06-27-2008, 07:41 PM -
JToggleButton Demonstration
By Java Tip in forum javax.swingReplies: 0Last Post: 06-26-2008, 07:38 PM -
Ftp client demonstration
By Java Tip in forum java.netReplies: 0Last Post: 04-07-2008, 08:11 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks