4.x 运行需 Java 11,构建需 JDK 25,老项目需选 3.x 或 2.6.x;代码补全、拼写检查需另装 AutoComplete、SpellChecker 等姊妹库
RSyntaxTextArea
bobbylightBSD-3-Clause活跃维护给 Java Swing 应用嵌入带语法高亮和代码折叠的文本编辑器组件,省去自己实现编辑器底层逻辑的麻烦。
A syntax highlighting, code folding text editor for Java Swing applications.
Maven 依赖:com.fifesoft:rsyntaxtextarea:XXX
构建:./gradlew build --warning-mode allREADME 未说明,仅要求 Java 运行环境:RSTA 4.x 需 JRE 11,3.x 需 JRE 8
给 Java Swing 应用嵌入语法高亮与代码折叠的文本编辑器组件
给 Java Swing 应用嵌入带语法高亮和代码折叠的文本编辑器组件,省去自己实现编辑器底层逻辑的麻烦。
核心能力
- 开箱支持 50+ 编程语言的语法高亮
- 内置代码折叠与查找替换功能
- 作为 JTextComponent 子类可直接放入 Swing 界面
- 可通过 JFlex 等工具扩展新语言高亮
- 配套 AutoComplete、SpellChecker 等扩展库
容易踩的坑
- 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 theFileTypeUtilutility class.Highlights
🔧
.envfiles recognized byFileTypeUtil(#720)4.0.0 added support for sytnax highlighting and code folding of
.envfiles.FileTypeUtilis 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.🔧
.vhdland.ps1files recognized byFileTypeUtil(#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
- 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:
- 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)
- Java 11 is the first LTS Java release that supported high DPI screens (Retina, 4k, etc.), which we can fully take advantage of
- 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 callsetEolMarker(String)to set a custom value to render. The default has also been changed to the more appropriate↲.Default Customized 🎁 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.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
Before After 🎁 FocusableTip: Now usable on any
JComponent, not justJTextAreas (@opeongo)New Contributors
- @opeongo made their first contribution in https://github.com/bobbylight/RSyntaxTextArea/pull/660
Full Changelog: https://github.com/bobbylight/RSyntaxTextArea/compare/3.6.2...3.6.3
- 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.
Before After 🔧 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 setslastSaveOrLoadTime
🎁 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:
Before After New Contributors
- @scyt01 made their first contribution in https://github.com/bobbylight/RSyntaxTextArea/pull/628
- @DJ-Raven made their first contribution in https://github.com/bobbylight/RSyntaxTextArea/pull/651
Full Changelog: https://github.com/bobbylight/RSyntaxTextArea/compare/3.6.0...3.6.2
- Calling
- 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
- Fix #612: Fix license link in maven config by @bobbylight in https://github.com/bobbylight/RSyntaxTextArea/pull/615
- Fix #613: Tweak language of BSD 3-clause license to match official ve… by @bobbylight in https://github.com/bobbylight/RSyntaxTextArea/pull/616
- Bump actions/setup-java from 4 to 5 by @dependabot[bot] in https://github.com/bobbylight/RSyntaxTextArea/pull/630
- Bump gradle/actions from 4 to 5 by @dependabot[bot] in https://github.com/bobbylight/RSyntaxTextArea/pull/632
- Bump github/codeql-action from 3 to 4 by @dependabot[bot] in https://github.com/bobbylight/RSyntaxTextArea/pull/633
- Bump actions/checkout from 4 to 6 by @dependabot[bot] in https://github.com/bobbylight/RSyntaxTextArea/pull/635
- Security Fix: Potential XXE Vulnerability in load function by @scyt01 in https://github.com/bobbylight/RSyntaxTextArea/pull/628
- Get publishing to gradle working with gradle-nexus/publish-plugin by @bobbylight in https://github.com/bobbylight/RSyntaxTextArea/pull/638
New Contributors
- @scyt01 made their first contribution in https://github.com/bobbylight/RSyntaxTextArea/pull/628
Full Changelog: https://github.com/bobbylight/RSyntaxTextArea/compare/3.6.0...3.6.1
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
RSyntaxTextArea
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 Version | Required to build (JDK) | Required to run (JRE) |
|---|---|---|
| 4.x | 25 | 11 |
| 3.x | 17 | 8 |
| 2.6.x | 6 | 6 |
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.