Re: how do I veto a setSelected() on JCheckBox



You'd better work with ButtonModel.
It has method setSelected(boolean)
You may put your business logic here
to define if you need to call super.

Default model for JCheckBox is JToggleButton.ToggleButtonModel

rob wrote:
Hello all, I am confused as to how to do this?
I would like the change to veto a setSelected
when the event happens but not sure how to go about this.
If I am in the actionPerformed of a JCheckBox, I guess
at that point it is to late to veto right? I would liek to check
some business logic before allowing the check to take place
by using contstrained properties.

I was thinking I would have define my own checkbox like

MyVetoableCheckBox extends JCheckBox
{
void public setSelected(booleand b) { setVetableSelected(b); }

void public setVetableSelected(boolean b) throws
ProvertyVetoException
{

if( some business logic tells me not to allow the check )
{
Boolean oldValue = isSelected ? Boolean.TRUE : Boolean.FALSE;
Boolean newValue = selected ? Boolean.TRUE : Boolean.FALSE;
fireVetoableChange("selected", oldValue, newValue);
}
else
{
super.setSelected(b);
}
}

am I even approaching this right?

.


Quantcast