Read and edit a text file (Editor)

Another option would be to use JTextArea in a Swing app. Downside is you have to do your own event handling to add ‘Open’ and ‘Save’ buttons. Also draw() is non-functional with this approach.

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

javax.swing.JFrame frame;
java.awt.Canvas canvas;

JTextArea txtArea;

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

void textArea() {
  txtArea = new JTextArea();
  JScrollPane scrlPane = new JScrollPane(txtArea);
  scrlPane.setBounds(0, 40, _wndW, _wndH);
  frame.add(scrlPane);
  txtArea.setEditable(true);
 // txtArea.setFont(new Font("Menlo", Font.BOLD, 16));
  txtArea.setLineWrap(false);
  txtArea.setWrapStyleWord(true);
  txtArea.repaint();
}

void buildWnd(){
  textArea();
}

void setup() {
  frame = (javax.swing.JFrame) ((processing.awt.PSurfaceAWT.SmoothCanvas) surface.getNative()).getFrame();
  canvas = (processing.awt.PSurfaceAWT.SmoothCanvas) ((processing.awt.PSurfaceAWT)surface).getNative();  
  frame.setBounds(500, 300, _wndW, _wndH);
  frame.remove(canvas);
  surface.setTitle("JTextArea Demo");
  
  javax.swing.SwingUtilities.invokeLater(new Runnable() {
    public void run() {
      buildWnd(); // Builds components on EventDispatchThread
    }
  }
  );
}