RSyntaxTextArea embedded in an application

Help
Dom
2005-05-20
2013-05-28
  • Dom

    Dom - 2005-05-20

    I'd like to embed a RSyntaxTextArea in an application. I tried to wite a little program to try that, and I have a NPE.

      public static void main(String[] args)
      {
        JFrame frame = new JFrame();
        RSyntaxTextArea rSyntaxTextArea = new RSyntaxTextArea();
        rSyntaxTextArea.setSyntaxEditingStyle(RSyntaxTextArea.JAVA_SYNTAX_STYLE);
        RTextScrollPane rTextScrollPane = new RTextScrollPane(80, 40, rSyntaxTextArea, true);
        frame.getContentPane().add(rTextScrollPane);
        frame.setVisible(true);
      }

       [java] Exception in thread "main" java.lang.NullPointerException
        [java]     at org.fife.ui.rsyntaxtextarea.RSyntaxTextArea.refreshFontMetrics(Unknown Source)
        [java]     at org.fife.ui.rsyntaxtextarea.RSyntaxTextArea.addNotify(Unknown Source)
        [java]     at java.awt.Container.addNotify(Container.java:2500)
        [java]     at javax.swing.JComponent.addNotify(JComponent.java:4436)
        [java]     at java.awt.Container.addNotify(Container.java:2500)
        [java]     at javax.swing.JComponent.addNotify(JComponent.java:4436)
        [java]     at java.awt.Container.addNotify(Container.java:2500)
        [java]     at javax.swing.JComponent.addNotify(JComponent.java:4436)
        [java]     at java.awt.Container.addNotify(Container.java:2500)
        [java]     at javax.swing.JComponent.addNotify(JComponent.java:4436)
        [java]     at java.awt.Container.addNotify(Container.java:2500)
        [java]     at javax.swing.JComponent.addNotify(JComponent.java:4436)
        [java]     at javax.swing.JRootPane.addNotify(JRootPane.java:680)
        [java]     at java.awt.Container.addNotify(Container.java:2500)
        [java]     at java.awt.Window.addNotify(Window.java:458)
        [java]     at java.awt.Frame.addNotify(Frame.java:501)
        [java]     at java.awt.Window.show(Window.java:505)
        [java]     at java.awt.Component.show(Component.java:1300)
        [java]     at java.awt.Component.setVisible(Component.java:1253)

    What's wrong with my code ? Did I misunderstood something ?

     
    • Robert Futrell

      Robert Futrell - 2005-05-21

      Hello,

      Try adding this line after creating your instance of the text area:

      rSyntaxTextArea.restoreDefaultSyntaxHighlightingColorScheme();

      I'm not sure why I don't have this done automatically in the RSyntaxTextArea constructor; I guess because RText sets the highlighting scheme to whatever the user last saved it as, so there was no need to initialize it with default values.  I think I'll change this in the next RText release, as I do want RSyntaxTextArea to be able to be used standalone.

      You can also set a custom highlighting scheme via the method:

      setSyntaxHighlightingColorScheme(SyntaxHighlightingColorScheme scheme);

      This is useful if you want to change the fonts or colors used for any tokens.

      Let me know if this helps!  And if you use it in an application you make publically available (such as on SourceForge), I'd love to hear about it!

       
      • Dom

        Dom - 2005-05-22

        Thanks a lot Robert ! It works !

        I might use your work in an internal tool in order to manage script code. This tool won't be public. I'd like to thank you for the great work you did !!!

         

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks