Home

Awesome

Build Status Coverage Status

RSyntaxTextArea is a customizable, syntax highlighting text component for Java Swing applications. Out of the box, it supports syntax highlighting for 40+ programming languages, code folding, search and replace, and has add-on libraries for code completion and spell checking. Syntax highlighting for additional languages can be added via tools such as JFlex.

RSyntaxTextArea is available under a modified BSD license. For more information, visit http://bobbylight.github.io/RSyntaxTextArea/.

Available in the Maven Central repository (com.fifesoft:rsyntaxtextarea:XXX). SNAPSHOT builds of the in-development, unreleased version are hosted on Sonatype.

Building

RSyntaxTextArea uses Gradle to build. To compile, run all unit tests, and create the jar, run:

./gradlew build

RSTA requires a Java 8 JDK to compile, but builds classes with Java 6 binary compatibility if possible (and indeed, the artifacts in Maven Central are Java 6-compatible). To that end, the boot classpath will be set to accommodate this if a variable java6CompileBootClasspath is set to the location of rt.jar in a Java 6 JDK. This can be added to <maven-home>/gradle.properties if desired, to avoid diffs in the project's gradle.properties.

Example Usage

RSyntaxTextArea is simply a subclass of JTextComponent, so it can be dropped into any Swing application with ease.

import javax.swing.*;
import org.fife.ui.rtextarea.*;
import org.fife.ui.rsyntaxtextarea.*;

public class TextEditorDemo extends JFrame {

   public TextEditorDemo() {

      JPanel cp = new JPanel(new BorderLayout());

      RSyntaxTextArea textArea = new RSyntaxTextArea(20, 60);
      textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA);
      textArea.setCodeFoldingEnabled(true);
      RTextScrollPane sp = new RTextScrollPane(textArea);
      cp.add(sp);

      setContentPane(cp);
      setTitle("Text Editor Demo");
      setDefaultCloseOperation(EXIT_ON_CLOSE);
      pack();
      setLocationRelativeTo(null);

   }

   public static void main(String[] args) {
      // Start all Swing applications on the EDT.
      SwingUtilities.invokeLater(new Runnable() {
         public void run() {
            new TextEditorDemo().setVisible(true);
         }
      });
   }

}

Sister Projects

RSyntaxTextArea provides syntax highlighting, code folding, and many other features out-of-the-box, but when building a code editor you often want to go further. Below is a list of small add-on libraries that add more complex functionality:

Getting Help