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.