0

i have a project that has a JEditorPane in netbeans, at the moment i have this being populated with a chosen .java file. what i would like to happen do is when the java file is loaded the syntax is colored appropriately so that it is easy to read other then the current plain text it is now.

Does anybody have any ideas on how to do this as i am unable to find any good examples of this online?

EDIT: ANSWER

I got this to finally work, i added the JSyntaxPane jar file to my classpath (jsyntaxpane-0.9.5-b29.jar to be exact) then i added the following two lines of code to get it working for my JEditorPane.

jsyntaxpane.DefaultSyntaxKit.initKit();
JEditorPane.setContentType("text/java");

This can also be used on the following languages: JavaScript, Properties, Groovy, C, C++, XML, SQL, Ruby and Python... just by simply changing text/java to text/LANGUAGE_YOU_WANT in the above code

newSpringer
  • 1,018
  • 10
  • 28
  • 44

1 Answers1

2

I would suggest to use RSyntaxTextArea (see http://fifesoft.com/rsyntaxtextarea/).

It's very easy to integrate and works great. The documentation contains an example, which shows how to integrate a RSyntaxtTextArea for Java-Syntax-Hightlighting:

http://fifesoft.com/rsyntaxtextarea/examples/example1.php

Dieter Rehbein
  • 941
  • 8
  • 16
  • does this have to be added manually to the form or can you add this as a feature in Netbeans GUI builder... as i am creating the project using the GUI builder? – newSpringer May 23 '12 at 15:41
  • I've never used Netbeans, so I have no idea. But this may help: http://stackoverflow.com/questions/816286/how-to-include-custom-panel-with-netbeans-gui-builder – Dieter Rehbein May 23 '12 at 19:22
  • Thanks for the help, it looks like it would work that way alright but i didnt actually try it as i managed to solve the problem a different way, i added the answer into my question in case anyone who see's the question wants to know how to solve it – newSpringer May 24 '12 at 07:59