Skip to content

Visual Feature Overview

Peter Froud edited this page May 24, 2023 · 7 revisions

RSyntaxTextArea has a large amount of ways to customize both its appearance and functionality. Because this is a rather large project, this page provides a visual overview of many of the cool features RSTA provides. That way you don't have to trawl through the API to discover them all.

NOTE: This is a work in progress.

Syntax Highlighting

RSTA knows how to syntax highlight 48 programming languages (and growing!), and is the main reason most folks use this library. Further, if the language you want to render isn't supported, you can implement your own syntax highlighting engine.
Related API: setSyntaxEditingStyle(String)

image

Code Folding

Code folding is supported for 32 languages (and growing)! To enable code folding in RSTA, call setCodeFoldingEnabled(true).
Related API: setCodeFoldingEnabled(boolean)

image

Paste as Styled Text

Text copied out of RSTA can be pasted into other applications with fonts and colors preserved.
Related API: copyAsStyledText(), copyAsStyledText(Theme)

Paste History

Pressing Ctrl + Shift + V (Cmd + Shift + V on Macs) will display a "Clipboard History" popup, allowing you to select from the most recent 10 or so items in your copy/paste buffer. This is useful e.g. when you're doing a lot of manual moving around of code.
Related API: n/a

image

File Loading/Saving

While the RSyntaxTextArea class has all of the code editing logic, there is a TextEditorPane subclass that provides most of the I/O features needed by an application - loading and saving files, managing the file's dirty and read-only state, and more. If your application allows the user to open, edit, and save files, you should probably consider using TextEditorPane over raw RSyntaxTextArea.
Related API: TextEditorPane.load(FileLocation, String)

Theming

The fonts and colors used in the editor, as well as surrounding components (line number list, ErrorStrip, etc.). You can use this to easily make your application themeable, for example, support both a light mode and a dark mode (provided you also update the LookAndFeel accordingly for all the other components). You can use any of the themes that come packaged with RSTA, or create your own. More information can be found in Example: Setting the theme.
Related API: Theme.load(InputStream), Theme.apply(RSyntaxTextArea)

image image image image

Bracket Matching

RSTA will highlight the "matched bracket" if the caret is on a paired bracket. This works for all languages where curly braces, square brackets, and/or parens are semantically significant. This feature is enabled by default.
Related API: setBracketMatchingEnabled(boolean), setPaintMatchedBracketPair(boolean)

image

Matched Bracket Popup

When the caret is on a closing bracket, and the paired opening bracket is off-screen, a tool tip will show the line containing the matched bracket to provide helpful context about the current code block. This feature is enabled by default.
Related API: setShowMatchedBracketPopup(boolean)

Marking Occurrences of the current token

All occurrences of the token at the caret position will be marked in the file. This occurs after a slight delay to avoid possible performance reasons in large files, but that delay is configurable. Note the types of tokens that RSTA will mark occurrences of depends on the programming language being rendered, e.g. typically variable names and identifiers will use this feature.
Related API: setMarkOccurrences(boolean), setMarkOccurrencesDelay(int)

image

Hyperlinks

Many languages automatically identify hyperlinks in comments. Ctrl+clicking them (or Cmd+clicking on Macs) will open the URL in a browser. This feature is enabled by default.
Related API: setHyperlinksEnabled(boolean), setLinkScanningMask(int), setHyperlinkForeground(Color)

image

Automatically Close Curly Braces

For languages that use curly braces to denote code blocks, the "closing" curly brace will be automatically inserted when Enter is pressed, if necessary. This feature is enabled by default.
Related API: setCloseCurlyBraces(boolean)

Automatically Close XML Tags

XML, MXML, and BBCode will all automatically insert the closing markup tag when </ is typed in the editor. If you don't want this feature, you can turn it off by calling e.g. XMLTokenMaker.setCompleteCloseTags() (and identically-named methods for other TokenMaker implementations for other languages).
Related API: XMLTokenMaker.setCompleteCloseTags(boolean) and related methods on sister classes

Note this feature can also be enabled in HTMLTokenMaker, but is disabled by default as many HTML tags are self-closing, and this feature isn't smart enough to know when that is the case.

Bookmarking Lines

This is a feature commonly found in IDE's. Press Ctrl + F2 (Cmd + F2 on Macs) to toggle whether a specific line in an open file has a bookmark, then use F2/Shift + F2 to automatically skip to the next or prior bookmark. Note if you want to use this feature, you need to manually enable it, and also supply your own icon (to ensure it looks good with the overall theme of your application):
Related API: Gutter.setBookmarkingEnabled(boolean), Gutter.setBookmarkIcon(Icon)

RSyntaxTextArea textArea = new RSyntaxTextArea(...);
textArea.setSyntaxEditingStyle(SYNTAX_STYLE_JAVA);
scrollPane = new RTextScrollPane(textArea, true);
// Enable bookmarking:
Gutter gutter = scrollPane.getGutter();
gutter.setBookmarkingEnabled(true);
URL url = getClass().getResource("bookmark.png");
gutter.setBookmarkIcon(new ImageIcon(url));

image

Secondary Language Highlighting

For languages where "secondary languages" appear (e.g. JavaScript in HTML), the secondary languages can be rendered with a different background color to easily spot them. This is particuarly useful in generated, or otherwise dense, code. This feature is enabled by default.
Related API: RSyntaxTextArea.setHighlightSecondaryLanguages(boolean)

image

Visible Whitespace

Both spaces and tabs can be rendered in the editor, as well as the end-of-line character to help you identify trailing whitespace.
Related API: setWhitespaceVisible(boolean), setEOLMarksersVisible(boolean)

image

Code Templates

Code templates allow you to define shortcuts for commonly-typed code, for exmaple, psvm for public static void main in Java. For more information on this feature, see Example: Code Templates. Also note that, if you need more flexibility, the sister AutoComplete library provides a much more powerful means of code completion.
Related API: setTemplatesEnabled(boolean), saveTemplates()

Margin Line

If you want a visual indicator to avoid writing lines longer than say 120 characters, you can call setMarginLineEnabled(true) to draw a line at that offset. This line is colored as part of the selected Theme, and can also be chaanged programmatically.
Related API: setMarginLineEnabled(boolean), setMarginLineColor(Color), setMarginLinePosition(int)

Tab Lines

RSyntaxTextArea can render tab offsets to show how many levels lines of code are indented. This property is enavbled by default. Like all other properties, the color of these lines are handled by the installed Theme by default.
Related API: setPaintTabLines(boolean), setTabLineColor(Color)

Active Line Range Rendering

Some languages, particularly those that use curly braces to denote code blocks, can have special rendering in the Gutter to indicate the scope/code block the caret is currently in.
Related API: n/a