Java Swing How to - Customize the JEditorPane border








Question

We would like to know how to customize the JEditorPane border.

Answer

import java.awt.Color;
import java.awt.FlowLayout;
/*from w ww. j  a va  2  s .c  o  m*/
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.WindowConstants;
import javax.swing.border.Border;
import javax.swing.border.LineBorder;

public class Main {

  public static void main(String[] args) {
    JFrame jFrame = new JFrame();
    jFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    jFrame.setSize(400, 300);
    JPanel panel = new JPanel(new FlowLayout());
    jFrame.setContentPane(panel);

    JEditorPane editor = new JEditorPane();
    new Main().remove_border(editor);
    panel.add(editor);

    jFrame.setVisible(true);
  }

  private Border b = new LineBorder(Color.black, 1);

  void remove_border(JEditorPane com) {
    com.setBorder(b);
  }

}