Java Swing How to - Store and Render Text with Tabs with JEditorPane








Question

We would like to know how to store and Render Text with Tabs with JEditorPane.

Answer

import java.awt.Dimension;
/*  ww w  .j  av  a  2s. c  om*/
import javax.swing.JEditorPane;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;

public class Main {
  public static void main(String[] args) {
    final JEditorPane editPane1 = new JEditorPane("text/html",
        "Try ty\tping some tabs");
    editPane1.setPreferredSize(new Dimension(400, 300));
    JOptionPane.showMessageDialog(null, new JScrollPane(editPane1));
    JOptionPane.showMessageDialog(null, new JScrollPane(new JEditorPane(
        "text/html", editPane1.getText()))); 
  }
}