personalized jCheckBox
hi all, first of all sorry for terrible english..
Does anybody know how can I obtain (I think by extension and by override some methods but I don't know which) a dummy JCheckBox that remain ALWAYS selected?
I want to initial setSelected(true), and when someone click (or use keyboard space) above it, not change his state.
I can't use setEnable(false) because I don't want to change his format (black font and all base-features).
Thanks a lot,
-nicola b.
[495 byte] By [
_nicolaa] at [2007-11-26 19:19:06]

I bet that would work. Myself, I would tweak the underlying model, because it's
not the JCheckBox component you're really changing but its selection model:
import javax.swing.*;
public class StaticToggleButtonModel extends JToggleButton.ToggleButtonModel {
public StaticToggleButtonModel(boolean selected) {
super.setSelected(selected);
}
public void setSelected(boolean b) {}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable(){
public void run() {
JPanel cp = new JPanel();
JCheckBox on = new JCheckBox("always on");
on.setModel(new StaticToggleButtonModel(true));
cp.add(on);
JCheckBox off = new JCheckBox("always off");
off.setModel(new StaticToggleButtonModel(false));
cp.add(off);
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setContentPane(cp);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
}
});
}
}