RSyntaxTextArea

bobbylightBSD-3-Clause活跃维护

给 Java Swing 应用嵌入带语法高亮和代码折叠的文本编辑器组件,省去自己实现编辑器底层逻辑的麻烦。

A syntax highlighting, code folding text editor for Java Swing applications.

4.0.1发布于 2026-07-26 21:40 UTC1,261star270fork同步于 2026-11-10 11:49 UTC

怎么上手

由 README 提炼,执行前请确认
Maven 依赖:com.fifesoft:rsyntaxtextarea:XXX
构建:./gradlew build --warning-mode all
硬件要求按 README 说明

README 未说明,仅要求 Java 运行环境:RSTA 4.x 需 JRE 11,3.x 需 JRE 8

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

给 Java Swing 应用嵌入语法高亮与代码折叠的文本编辑器组件

给 Java Swing 应用嵌入带语法高亮和代码折叠的文本编辑器组件,省去自己实现编辑器底层逻辑的麻烦。

核心能力

  • 开箱支持 50+ 编程语言的语法高亮
  • 内置代码折叠与查找替换功能
  • 作为 JTextComponent 子类可直接放入 Swing 界面
  • 可通过 JFlex 等工具扩展新语言高亮
  • 配套 AutoComplete、SpellChecker 等扩展库

容易踩的坑

4.x 运行需 Java 11,构建需 JDK 25,老项目需选 3.x 或 2.6.x;代码补全、拼写检查需另装 AutoComplete、SpellChecker 等姊妹库

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本4.0.1
  1. 4.0.1最新正式版2026-07-26 · 2026-07-26 21:40 UTC

    Precompiled jars are available in Maven Central (com.fifesoft:rsyntaxtextarea:4.0.1). This release is a minor update that is only really required from 4.0.0 if you use the FileTypeUtil utility class.

    Highlights

    🔧 .env files recognized by FileTypeUtil (#720)

    4.0.0 added support for sytnax highlighting and code folding of .env files. FileTypeUtil is a utility class that can (among other things) take a file name and figure out how RSTA should syntax highlight it. This utility wasn't updated for .env, .env.sample, etc. This release fixes that oversight.

    🔧 .vhdl and .ps1 files recognized by FileTypeUtil (#720)

    Similar to the above. These two file types - VHDL and PowerShell - were accidentally not handled by FileTypeUtil. This release makes these file types detected and properly identified by FileTypeUtil.

    Full Changelog: https://github.com/bobbylight/RSyntaxTextArea/compare/4.0.0...4.0.1

  2. 4.0.02026-07-18 · 2026-07-18 02:13 UTC
    查看更新说明

    Precompiled jars are available in Maven Central (com.fifesoft:rsyntaxtextarea:4.0.0). This is a major release that bumps the minimum JRE requirement to 11 to take advantage of HiDPI APIs.

    Highlights

    🔧 The minimum required JRE is now 11 (#524)

    The 3.x versions of RSTA ran on Java 8 and newer. The decision to bump the minimum required JRE was made for several reasons:

    1. Java 8 is ancient - end of (premier) support was 4 years ago, and Java 11 - also ancient - and came out 8 years ago (September 2018)
    2. Java 11 is the first LTS Java release that supported high DPI screens (Retina, 4k, etc.), which we can fully take advantage of
    3. This allows us to modernize the codebase

    🎁 Support customizing the end-of-line marker (#708)

    Previously, if setEolMarkersVisible(true) was called, the editor always rendered at the end of each line. Clients can now call setEolMarker(String) to set a custom value to render. The default has also been changed to the more appropriate ↲.

    DefaultCustomized

    🎁 Add syntax highlighting and code folding of .env files (#709)

    Like it says on the tin.

    .env syntax highlighting and code folding

    🎁 Allow clients to define their own matched bracket pairs (#693)

    The library no longer hard-codes [, (, and { as bracket types to match. Now, TokenMakers specify which chars, if any, represent "brackets" to match in them. This allows other languages to use other chara ters.

    New Contributors

    • @ptorngren
    • @p2rsoftware
    • @sesquialtera87

    Full Changelog: https://github.com/bobbylight/RSyntaxTextArea/compare/3.6.3...4.0.0

  3. 3.6.32026-06-08 · 2026-06-08 00:55 UTC
    查看更新说明

    Precompiled jars are available in Maven Central (com.fifesoft:rsyntaxtextarea:3.6.3). This is an especially important update if you render Markdown.

    Highlights

    🎁 Markdown: Fix rendering bug when '#' is not in a header

    BeforeAfter

    🎁 FocusableTip: Now usable on any JComponent, not just JTextAreas (@opeongo)

    New Contributors

    Full Changelog: https://github.com/bobbylight/RSyntaxTextArea/compare/3.6.2...3.6.3

  4. 3.6.22026-02-28 · 2026-02-28 03:44 UTC
    查看更新说明

    Precompiled jars are available in Maven Central (com.fifesoft:rsyntaxtextarea:3.6.2).

    Highlights

    🎁 Added PowerShell Syntax Highlighting by @Var7600 in https://github.com/bobbylight/RSyntaxTextArea/pull/606

    Syntax highlighting of PowerShell is now supported.

    PowerShell

    🎁 Syntax highlighting improvement for INI by @sesquialtera87 in https://github.com/bobbylight/RSyntaxTextArea/pull/622

    Issues around strings, comments, and square brackets in values were all fixed.

    BeforeAfter

    🔧 Minor tweaks to TextEditorPane by @bobbylight in https://github.com/bobbylight/RSyntaxTextArea/pull/648

    • Calling reload() on a local, new/unsaved file is now a no-op, and doesn't throw an exception
    • Calling load() now sets lastSaveOrLoadTime

    🎁 Add fold indicator background by @DJ-Raven in https://github.com/bobbylight/RSyntaxTextArea/pull/651

    The editor now supports a background color for collapsed fold lines. Themes can define this property as well.

    Collapsed fold line background

    🔧 Fix FR encoding error in focusable tips by @bobbylight in https://github.com/bobbylight/RSyntaxTextArea/pull/654

    The accented character was incorrectly defined for focusable tooltips in French:

    BeforeAfter

    New Contributors

    Full Changelog: https://github.com/bobbylight/RSyntaxTextArea/compare/3.6.0...3.6.2

  5. 3.6.12025-12-29 · 2025-12-29 01:40 UTC
    查看更新说明

    Precompiled jars are available in Maven Central (com.fifesoft:rsyntaxtextarea:3.6.1).

    Highlights

    No new features, this release is primarily to bump dependencies and get publishing to Maven Central working again.

    What's Changed

    New Contributors

    Full Changelog: https://github.com/bobbylight/RSyntaxTextArea/compare/3.6.0...3.6.1

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    RSyntaxTextArea

    Java Build Java Build Maven Central codecov

    RSyntaxTextArea is a customizable, syntax highlighting text component for Java Swing applications. Out of the box, it supports syntax highlighting for 50+ 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 BSD 3-Clause 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.

    Please see the wiki for an overview of features and a deep-dive into the code!

    Building

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

    ./gradlew build --warning-mode all
    

    RSTA 4.0 and later requires Java 11 to run. If you need to support older Java versions, use the RSTA version specified in the following table:

    RSTA VersionRequired to build (JDK)Required to run (JRE)
    4.x2511
    3.x178
    2.6.x66

    Demos

    There are several simple demo applications in the RSyntaxTextAreaDemo submodule. To run the "main" one, which shows off syntax highlighting and code folding for several languages as well as several common configuration options, run:

    ./gradlew RSyntaxTextAreaDemo:run
    

    Example Usage

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

    import javax.swing.*;
    import java.awt.BorderLayout;
    
    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 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:

    • AutoComplete - Adds code completion to RSyntaxTextArea (or any other JTextComponent).
    • RSTALanguageSupport - Code completion for RSTA for the following languages: Java, JavaScript, HTML, PHP, JSP, Perl, C, Unix Shell. Built on both RSTA and AutoComplete.
    • SpellChecker - Adds squiggle-underline spell checking to RSyntaxTextArea.
    • RSTAUI - Common dialogs needed by text editing applications: Find, Replace, Go to Line, File Properties.

    Getting Help