Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / January 2006

Tip: Looking for answers? Try searching our database.

automatic color in JTextPane

Thread view: 
Bach 1 1/2C - 20 Jan 2006 14:34 GMT
Hello big brains.  I'm interested in your advice.  I'm solving a
problem in my own particular way and I was wondering if you could tell
me if it makes sense?  Perhaps there's an easier way or maybe even a
mechanism already built into swing that I'm unaware of.  Dunno.

When I use vi on my Linux, it assigns color to important stuff -
reserved words, text strings, comments, and more - and it does this
based on file type.  So, C++, Java, XML, shell scripts, all have
special handlers in my vi and I like it very much.  (It's really pretty
common.  Why, even MSoft Visual C++ can do it.)  I would like all my
JTextPanes in my GUI's to do this, also.  I use
StyledDocument.setCharacterAttributes() and that works nicely but the
trick is to pick out the important stuff in a document and color it
quickly so that it happens while the user is typing and without a
noticeable impact on the computer's performance.  In addition, I use
lots of JTextPanes for different types of stuff and I would not like to
write special purpose code for each type of stuff.  I would like to
have one thing that I can use for all the different types.

So, I put a whole bunch of regular expressions and their associated
text attributes into a properties file and during editing I try to
match the user's chars against these regular expressions.  The regular
expressions are in groups, so that at run time I can select the group I
want used.  During editing, I'm careful to rexamine only the portions
of the document that might be affected by the new input (or deletion).
It seems to work fairly well.

Am I missing something?  It seems as though this ought to be built in
somewhere or downloadable.

TIA
Oliver Wong - 25 Jan 2006 22:31 GMT
> When I use vi on my Linux, it assigns color to important stuff -
> reserved words, text strings, comments, and more - and it does this
> based on file type.  So, C++, Java, XML, shell scripts, all have
> special handlers in my vi and I like it very much.  (It's really pretty
> common.  Why, even MSoft Visual C++ can do it.)  I would like all my
> JTextPanes in my GUI's to do this, also.

The name of that feature is "syntax highlighting".

[...]

> Am I missing something?  It seems as though this ought to be built in
> somewhere or downloadable.

Try http://ostermiller.org/syntax/

   - Oliver
Bach 1 1/2C - 28 Jan 2006 14:40 GMT
Thanks.  Just what I was looking for.  I'll try it out.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.