• Post Reply Bookmark Topic Watch Topic
  • New Topic

Syntax highlighting in JTextPane.  RSS feed

 
Ranganath Junpal
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

I am building a simple to hightlight couple of keywords. I am using the JTextpane. I have also written a class extending the DefaultStyledDocument.
when i say jtextPane.setDocument(defstyledDocument),My editor works just fine as expected like when i type the keywords it gets highlighted. But when i open an .java file and set the jtextPane.setPane(file.toURL) . The content in the JTextPane ie the file content doesnt high light the keywords. May i know the reason ?

Thank you
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when i open an .java file and set the jtextPane.setPane(file.toURL) . The content in
the JTextPane ie the file content doesnt high light the keywords

Look at the first sentence in the first paragraph in the Method Detail section of the
EditorKit setPage(URL url) method. A new default document is set. So we need to find a
way to have your DefaultStyledDocument extension be the default document for the textPane.
One way to do this is to set an EditorKit on the textPane and specify your
DefaultStyledDocument extension as the default document in the createDefaultDocument
method. I tried this in this test app and it worked okay.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!