# CodeFolding in RSyntaxTextArea

**URL:** <https://discourse.processing.org/t/codefolding-in-rsyntaxtextarea/47161>\
**Category:** Gallery\
**Created:** [September 17, 2025, 3:03am UTC](https://discourse.processing.org/t/codefolding-in-rsyntaxtextarea/47161 "2025-09-17T03:03:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [September 17, 2025, 3:03am UTC](https://discourse.processing.org/t/codefolding-in-rsyntaxtextarea/47161/1 "2025-09-17T03:03:43Z")

</div>

The following source code demonstrates code folding in RSyntaxTextArea. I downloaded `rsyntaxtextarea-3.6.0.jar` from the link below and installed it in Processing’s ‘_libraries_’ folder in a folder that I created and entitled ‘_RSyntaxTextArea_’. Inside of this folder I created another folder entitled ‘_library_’ and copy/pasted the .jar file into it.

I found a recent _rsyntaxtextarea-3.6.0.jar_ here: [https://repo1.maven.org/maven2/com/fifesoft/rsyntaxtextarea/3.6.0/](https://repo1.maven.org/maven2/com/fifesoft/rsyntaxtextarea/3.6.0/)

If you use an older .jar file, code folding may not work; it was not present in earlier .jar files. I’ve also included source code for a file that you may use for testing.

```processing
import java.awt.*;
import javax.swing.*;

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

JFrame frame;
RTextScrollPane txtScrlPane;
RSyntaxTextArea txtArea;

final int _wndW = 600;
final int _wndH = 600;

void buildWnd() {
  surface.setVisible(false);
  frame = new JFrame();
  frame.setBounds(100, 100, _wndW, _wndH);
  frame.setTitle("RSyntaxTextArea Demo");
  JPanel panel = new JPanel(new BorderLayout());
  txtArea = new RSyntaxTextArea();
  txtArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA);
  txtArea.setCodeFoldingEnabled(true);
  txtScrlPane = new RTextScrollPane(txtArea);
  panel.add(txtScrlPane);
  frame.setContentPane(panel);
  frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
  frame.setVisible(true);
}

void setup() {
  SwingUtilities.invokeLater(() -> {
    buildWnd();
  }
  );
}

```

**File for testing (copy/paste code into app created above):**

```processing
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

JFrame frame;

final int _wndW = 600;
final int _wndH = 600;

void buildWnd() {
  frame = new JFrame();
  frame.setBounds(100, 100, _wndW, _wndH);
  frame.setTitle("JFrame Demo");
  frame.setLayout(null);
  frame.setVisible(true);
}

void setup() {
  surface.setVisible(false);
  javax.swing.SwingUtilities.invokeLater(()-> {
    buildWnd(); // Builds components on EventDispatchThread
  }
  );
}

```

**CodeFolding Output:**

 ![oput](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/3/f/3fbbbb594fde40948a18333bcf664f5ddb4cf2cd.png)
