Java examples for Swing:JEditorPane
JEditorPane can understand three types of contents: text/plain, text/html, and text/rtf.
You can use the following code to display the text Hello, using the <h1> tag in HTML:
import java.io.IOException; import javax.swing.JEditorPane; public class Main { public static void main(String[] args) { try { JEditorPane htmlPane = new JEditorPane("https://www.java2s.com"); htmlPane.setContentType("text/html"); htmlPane.setText("<html><body><h1>Hello</h1></body></html>"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }