Any component that can take text can also make HTML text , which will be formatted according to HTML rules. this means you can easily add text decorated in a Swing component.
It must begin with the text “<html>”, then you can use the normal HTML tags. Note that it is not forced to include normal closing tag.
The ActionListener adds a new JLabel to the form, which also contains HTML text. However, this tag is not added during init () so that should call the validate () method of the container force a redrawing of the components (and thus display the new label). You can also use HTML text for JTabbedPane, JMenuItem, JToolTip, JRadioButton and JCheckBox.
Here is the example of HTML text on Swing Components
/* <applet code=HTMLText.class width=320 height=200> </applet> */ import javax.swing.*; import java.awt.event.*; import java.awt.*; public class HTMLText extends JApplet { JButton btnClick = new JButton("<html><b><font size=+1>" + "<center><i>Click Here!"); public void init() { Frame frm = (Frame)this.getParent().getParent(); frm.setTitle("HTML text on Swing Components"); btnClick.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { getContentPane().add(new JLabel("<html>"+ "<i><font size=+1> https://ecomputernotes.com ")); validate(); } }); Container container = getContentPane(); container.setLayout(new FlowLayout()); container.add(btnClick); } }