Results 1 to 7 of 7

Thread: Syntax Highlighting *RESOLVED*

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2001
    Location
    UK
    Posts
    222

    Syntax Highlighting *RESOLVED*

    Hello

    I have SQL generated and placed in a JTextPane.

    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.

  2. #2

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    May 2001
    Location
    UK
    Posts
    222

    Crude but effective

    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.

    Andy
    Attached Files Attached Files

  5. #5
    Hyperactive Member
    Join Date
    Feb 2002
    Location
    USA
    Posts
    432
    Dose anyone have a emplementation of this so i can see how to use it im sorta new and would like to try this out

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    May 2001
    Location
    UK
    Posts
    222

    Example

    Sure, here is a simple example,

    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!
    Attached Files Attached Files

  7. #7
    Hyperactive Member
    Join Date
    Feb 2002
    Location
    USA
    Posts
    432
    Cool Thank you

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width