Java tutorial
import java.awt.Color; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JTextPane; public class Main { public static void main(String[] args) throws Exception { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextPane editorPane = new JTextPane(); editorPane.setSelectedTextColor(Color.red); // set content as html // editorPane.setContentType("text/html"); editorPane.setText("<p color='#FF0000'>Cool!</p>"); // added <u></u> to underlone button JButton label = new JButton("button"); label.setAlignmentY(0.85f); label.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger() || e.getButton() == MouseEvent.BUTTON1) { JOptionPane.showMessageDialog(null, "Hello!"); } } }); editorPane.insertComponent(label); frame.getContentPane().add(editorPane); frame.pack(); frame.setVisible(true); } }