Skip to content

Instantly share code, notes, and snippets.

@DrPlantabyte
Created September 5, 2014 17:40
Show Gist options
  • Save DrPlantabyte/195325d3f675757eeb46 to your computer and use it in GitHub Desktop.
Save DrPlantabyte/195325d3f675757eeb46 to your computer and use it in GitHub Desktop.
How to display JavaScript syntax highlighting in Java with RSyntaxTextArea
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);
}
@DrPlantabyte
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment