Creating a JLabel with the text underlined

The easiest way is to use the HTML tag u. If you don’t want to use the HTML feature, check out How do I create an underlined JLabel without using HTML?

import java.awt.event.*;
import java.awt.font.*; 
import javax.swing.*;
import java.util.*;
import java.text.*;
import java.awt.*;
public class Main extends JFrame {
   public Main() {
      getContentPane().setLayout(new FlowLayout());
      JLabel label = new JLabel("<html><u>Underlined text with HTML</u></html>");
      addWindowListener(new WindowAdapter() {
         public void windowClosing(WindowEvent event) {
      setSize(300, 200);
   public static void main(String[] args) {
      (new Main()).show();