Java JLabel set disabled icon

Description

Java JLabel set disabled icon

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class Main extends JFrame {

  public Main() {
    super("Link JLabel with JTextField");

    setDefaultCloseOperation(EXIT_ON_CLOSE);

    JLabel nameLabel = new JLabel("Java demo from demo2s.com.");
    nameLabel.setDisabledIcon(new ImageIcon("icon.png"));
    nameLabel.setEnabled(false);/*  w  ww .j  a  v a2s. c om*/

    add(nameLabel);

  }

  public static void main(String[] args) {
    Main frame = new Main();
    frame.pack();
    frame.setVisible(true);
  }
}



PreviousNext

Related