• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Syntax highlighting in JTextPane.

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Would anybody like some fudge? I made it an hour ago. And it goes well with a tiny ad ...
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic