Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-25-2008, 04:30 PM
Moderator
 
Join Date: Nov 2007
Posts: 1,657
Java Tip will become famous soon enoughJava Tip will become famous soon enough
StyleRange Demonstration
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(); } }
__________________
Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
to our beloved Java Forums! (closes on July 27, 2008)
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
TableTree Demonstration Java Tip SWT 0 07-07-2008 06:57 PM
TreeViewer Demonstration Java Tip SWT 0 07-07-2008 06:54 PM
TreeCellRenderer Demonstration Java Tip javax.swing 0 06-27-2008 09:41 PM
JToggleButton Demonstration Java Tip javax.swing 0 06-26-2008 09:38 PM
Ftp client demonstration Java Tip java.net 0 04-07-2008 10:11 PM


All times are GMT +3. The time now is 08:41 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org