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]
# 1
Your english is good.Anyway, I guess you could just override the setSelected() method and keep it from updating the check box.
zadoka at 2007-7-9 21:35:04 > top of Java-index,Java Essentials,New To Java...
# 2

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);

}

});

}

}

DrLaszloJamfa at 2007-7-9 21:35:04 > top of Java-index,Java Essentials,New To Java...
# 3
THANKS A LOT DrLaszloJamf !!!I'm not already analize your code but I try to execute it and it seems work!!Another time, thanksRegards,-Nicola
_nicolaa at 2007-7-9 21:35:04 > top of Java-index,Java Essentials,New To Java...