public class HtmlArea extends JFrame{
private JEditorPane editor;
public HtmlArea() {
getContentPane().setLayout(new FlowLayout());
editor = new JEditorPane();
editor.setPreferredSize(new Dimension(400, 300));
editor.setEditable(false); //El usuario no podrá escribir
editor.setContentType("text/html"); //Le indicamos que ha de interpretar HTML
//Construimos el HTML en un String
String txt = "<html>Texto sin negrita --> Realizar pagos ✔<br>"
+ "Texto con <b>negrita</b> --> Realizar pagos <b>✔</b><br>"
+ "Texto <b>negrita</b> y <span style=\"color: blue\">color</span>--> Realizar pagos <b style=\"color: blue\">✔</b><br>"
+ "<p style=\"text-align:center\">Párrafo centrado</p><br>"
+ "Separadores horizontales de distintos anchos:<br>"
+ "<hr style=\"width: 75%\">"
+ "<hr style=\"width: 50%\">"
+ "<hr style=\"width: 25%\"><br>"
+ "Lista:<br>"
+ "<ul><li>Elemento 1</li><li>Elemento 2</li><li>Elemento 3</li></ul></html>";
//Le pasamos el texto HTML al editor para que lo muestre
editor.setText(txt);
add(editor);
setTitle("Prueba HTML");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
pack();
setVisible(true);
}
public static void main(String[] args) {
new HtmlArea();
}
}