Making a JLabel selectable

A common way is to create a JTextField and give the user the impression it’s a JLabel by changing some of its properties. Here’s an example:

Main.java:

import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
 
public class Main extends JFrame
{
   public Main() {
      getContentPane().setLayout(new FlowLayout());
      JLabel label = new JLabel("BWOAAHAHAHA, you can't select me!");
      JTextField textfield = new JTextField("Grab me instead!   ");
 
      // give the textfield the impression it's a label
      textfield.setBorder(null);
      textfield.setEditable(false);
      textfield.setForeground(UIManager.getColor("Label.foreground"));
      textfield.setFont(UIManager.getFont("Label.font"));
 
      getContentPane().add(label);
      getContentPane().add(textfield);
 
      addWindowListener(new WindowAdapter() {
         public void windowClosing(WindowEvent we) {
            System.exit(0);
         }
      });
   }
 
   public static void main(String [] args) {
      Main main = new Main();
      main.setSize(300, 300);
      main.setVisible(true);
   } 
}