I'd like to color all the special word differently from the user inputed word e.g. SELECT and FROM etc.. would be BLUE and the table names would be black...
you get the idea.
Iw as wondering if anyone had done this, or had any ideas how to do it?!
Cheers
Andy
Last edited by Andy_Hollywood; Aug 22nd, 2003 at 06:19 AM.
This is something very tricky I tried to understand for a long time, but never did.
You need all that stuff from javax.swing.text for it. You replace the EditorKit by a SQLEditorKit written by you, which provides a Document implementation and a View implementation. The View can actually be an existing one (not sure), the Document should be written by you. The document tree that you generate should consist of keyword nodes and one or more other node types (e.g. value, field name etc.). Then you apply styles to the nodes to provide the highlighting.
I couldn't find any proper examples, but if you want you can dig into the NetBeans source (www.netbeans.org) and find their syntax highlighter. It should be based on the same principle.
All the buzzt CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
I have found a solution, not brillaint, but effective enough for what was doing.
Its a styled documetn that basically scns through for keywords when ever you alter the text etc...
As the text (SQL) was never hopefully going to get that big, i'm happy using it this way, for the time being.
Sun offer a beter solution, but to be honesti could be bothered to write so many classes, and update the demo they had which was built for java 1.1 i think.
I've attached the .java file in case anyone want to have a look.
its two classes, compile and run the Window.java class.
Its should prduce a window with a JTextPane in it, with some syntax, one this works you can work through the code int he SyntaxDocument class, there are some comments etc.... if you need any more help let me know!