JLabel label = new JLabel("Click me"); label.setEnabled(false); // disable the label
JCheckBox checkBox = new JCheckBox("Enable Label"); JLabel label = new JLabel("Click me"); checkBox.addActionListener(e -> { if (checkBox.isSelected()) { label.setEnabled(true); // enable the label } else { label.setEnabled(false); // disable the label } });In this example, the label component is disabled by default. When the user selects the JCheckBox, the label is enabled, and when the user unselects the JCheckBox, the label is disabled. The javax.swing package library contains the classes and interfaces for creating the GUI components in Java Swing. The JLabel component is part of this package.