The Source for Java Technology Collaboration
User: Password:



Edgar Silva

Edgar Silva's Blog

Using the Java Source Editor and Syntax highlight in any JEditorPane

Posted by edgars on January 17, 2007 at 10:52 AM | Comments (2)

On the my new JSF Palette Components I've been doing, It allows users get any BackingBean (bean) from the Project, to make it possible, I was looking for on NetBeans Dev Wiki. And I get this entry: http://wiki.netbeans.org/wiki/view/DevFaqEditorJEPForMimeType . However, I think this might works on NetBeans 6.0, cause doing like this entry says ...

EditorKit kit = CloneableEditorSupport.getEditorKit("text/x-java");
JEditorPane jep = new JEditorPane();
jep.setEditorKit(kit);

I in fact did not have success. But, NetBeans Platform, offers great resources, as I did something similar to Greenbox for NetBeans , I did the following code for what I was needing:


      /** Creates new form JavaCodePanel */
    public JavaCodePanel() {
        initComponents();
        beanCode.setContentType("text/x-java");
        EditorKit kit = JEditorPane.createEditorKitForContentType("text/x-java");
        kit.install(beanCode);
        beanCode.setEditorKit(kit);
    }

On the code the beanCode is a JEditorPane, and now this will have the same actions you can see on default Java Editor.
Look on the following image this component working:


javacode.PNG
javacode2.PNG
javacode3.PNG

Bookmark blog post: del.icio.us del.icio.us Digg Digg DZone DZone Furl Furl Reddit Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment

  • You been a busy man !!!

    Haven't visited your blog for a little while. I've missed out on a bunch of cool stuff.

    Posted by: huntch on January 18, 2007 at 10:19 AM

  • That's it? Seems to be simple.

    What if I'd like to use that outside of NetBeans? Can you find out which jars are needed?

    Posted by: herkules on January 25, 2007 at 05:19 AM



Only logged in users may post comments. Login Here.


Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds