Created
September 5, 2014 17:40
-
-
Save DrPlantabyte/195325d3f675757eeb46 to your computer and use it in GitHub Desktop.
How to display JavaScript syntax highlighting in Java with RSyntaxTextArea
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
JPanel scriptPane = new javax.swing.JPanel(); | |
// ... | |
void addSyntaxTextArea() { | |
RSyntaxTextArea scriptArea = new RSyntaxTextArea(10, 20); | |
scriptArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVASCRIPT); | |
scriptArea.setCodeFoldingEnabled(true); | |
scriptArea.setAntiAliasingEnabled(true); | |
RTextScrollPane sp = new RTextScrollPane(scriptArea); | |
sp.setFoldIndicatorEnabled(true); | |
scriptPane.setLayout(new BorderLayout()); | |
scriptPane.add(sp); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My lab has been working with embedding scripting engines in our scientific instrument control software and JavaScript is the easiest to embed in a Java program. A colleague complained about the poor documentation for the RSyntax 3rd party library, so here's some sample code for how to use RSyntax.
Fortunately, RSyntax is self-contained and the above code is all you need to do for a feature-rich code editor that is on par with an IDE.