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
> Hello all, I am confused as to how to do this?
> I would like the change to veto a setSelected
[quoted text clipped - 27 lines]
>
> am I even approaching this right?
rob - 24 Feb 2006 16:42 GMT
thanks, i guess this would be much easier than messing
with vetos, maybe thats not even a valid way anyhow
> Hello all, I am confused as to how to do this?
> I would like the change to veto a setSelected
[quoted text clipped - 27 lines]
>
> am I even approaching this right?
JCheckBox inherits from JComponent, which has the method
addVetoableChangeListener, so it seems possible (though I haven't tested
it) that you could accomplish this by making your checkbox implement
VetoableChangeListener (or creating such internally) and calling that
method. Then the vetoableChange method will fire when any property of
the checkbox is going to be changed, passing a PropertyChangeEvent.
As I said, I haven't tried this with a checkbox. But I have done it
with a JInternalFrame. It implements the interface and adds itself as a
VetoableChangeListener. When vetoableChange is called, it checks to see
if the property being changed is its IS_CLOSED_PROPERTY value (see the
API Javadocs) and if it's being changed from Boolean.FALSE to
Boolean.TRUE. If this is the case, my logic checks to see if the
content warrants a save prompt. If the user says to cancel that close,
then I veto the change and the close never happens.
I don't see any properties in JCheckBox that immediately suggest
themselves as candidates, so it may not be possible to do this the way
I'm describing. But it seems worth a closer look. Otherwise, an
alternative approach would be in order, I think, since the concept you
outline above would necessarily let the user change the state and then
forcibly change it back.
On the other hand, you might also consider simply not enabling the
checkbox if your conditions won't allow its state to change. If it's
not enabled, a user can't very well click it to change its checked state.
= Steve =

Signature
Steve W. Jackson
Montgomery, Alabama
Thomas A. Russ - 24 Feb 2006 23:07 GMT
> > 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
...
> On the other hand, you might also consider simply not enabling the
> checkbox if your conditions won't allow its state to change. If it's
> not enabled, a user can't very well click it to change its checked state.
That was what I thought of as well.
It has the additional beneficial property of being pro-active and
visible. That means that the user isn't but in the situation of trying
to do something only to have the system then tell him it can't be done.
It is better to make this explicit and visible up front. It will save
the user time and aggravation, so I would consider it to be a much
superior solution. It isn't as if the user can enter something
arbitrary and unpredictable, so just have the code do the work in advance.

Signature
Thomas A. Russ, USC/Information Sciences Institute
> Hello all, I am confused as to how to do this?
> I would like the change to veto a setSelected
[quoted text clipped - 27 lines]
>
> am I even approaching this right?
Another option to consider is to disable the check box if it is not a
valid time to check it.

Signature
Knute Johnson
email s/nospam/knute/
rob - 24 Feb 2006 19:31 GMT
thanks all, i think the veto thing would not work because
"selected" is a property, but not a constrained property
so i may be out of luck. Disabled may be an option but havn't thought
it out to much, just thought intercepting the potential property change
prior to it actually changing would do the trick, but maybe not.
thanks all