Skip to main content

Using the Java Source Editor and Syntax highlight in any JEditorPane

Posted by edgars on January 17, 2007 at 10:52 AM PST

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

Related Topics >>