Why can't I set button model for JCheckBox
?
The following code works and draws a window with one single check box in the center. Check box is operational:
public class JCheckButton_Test {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
ButtonModel buttonModel = new DefaultButtonModel();
JCheckBox checkBox = new JCheckBox();
checkBox.setText("Check Box");
//checkBox.setModel(buttonModel);
JPanel controlPanel = new JPanel();
controlPanel.add(checkBox);
JFrame frame = new JFrame();
frame.add(controlPanel, BorderLayout.CENTER);
frame.pack();
frame.setSize(640, 200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
});
}
}
But if I add a model to the box (uncomment line) check box become non-operational (does not change if clicked).
Why?