Java Swing How to - Create JLabel with text








Question

We would like to know how to create JLabel with text.

Answer

/* w  w w.j a  v  a 2 s .  c o m*/
import javax.swing.JLabel;
import javax.swing.JOptionPane;

public class Main {
  public static void main(String[] args) {
    JLabel label = new JLabel("Username :");
    
    JOptionPane.showMessageDialog(null, label);
    
  }
}