Theming Support in RSyntaxTextArea

One cool new feature in the upcoming release of RSyntaxTextArea is theming support.  Currently, if you want to customize the fonts and colors used in RSTA, you have to programmatically use the SyntaxScheme and Style classes to do so.  This is actually very straightforward, but it also means you have to design your own UI if you want your users to be able to customize the editor in your application.  Many folks (not me :)) would find such a task tedious.

In the next release (and available for a preview in SVN), you’ll be able to completely customize RSTA via an XML file.  This allows you to externalize your customization logic from your application, and even deliver various “themes” if you so desire!

Theme XML is validated against the new theme.dtd.  You’ll notice that it allows you to set not only the fonts and colors used in the editor, but also those used by the gutter (assuming RSTA is wrapped in an RTextScrollPane).  There are a few sample themes already in the RSyntaxTextAreaDemo project.  These will probably get added to the main RSyntaxTextArea project, but won’t be a part of the actual library jar to avoid any more bloat.  Applications can feel free to ship these themes as-is, or modified, with themselves.

Using a theme couldn’t be simpler using the new Theme class:

   InputStream in = getClass().getResourceAsStream("/dark.xml");
   try {
      Theme theme = Theme.load(in);
      theme.apply(textArea);
   } catch (IOException ioe) {
      ioe.printStackTrace();
   }

Saving a Theme will be added once I have everything configurable via the XML.

Here’s an example of the “dark” theme currently checked in:

Dark Theme

Dark Theme

One Response to “Theming Support in RSyntaxTextArea”

  1. [...] Theming support via XML.  This allows for easily customizing RSTA to fit the color scheme of your application, easier saving/loading user-defined token styles, etc. [...]