Skip to main content

Drag on JCheckBox

7 replies [Last post]
heshamg
Offline
Joined: 2008-05-13

Hello ,

I have a JCheckBox that i assigned a MouseClicked() event listener to it to execute some code when it is being enabled/disabed.

When that JCheckBox is pressed and the mouse is dragged even 1 pixel then releasing the mouse, i see the JCheckBox case changed but the Click event is not executed.

Can i fix this somehow to continue execute the Mouse Click event ?

Thanks a lot

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
heshamg
Offline
Joined: 2008-05-13

Anthony ,

Sorry for being so late in replying.
I have used [b]TableModelListener[/b] and it solved my problem.

Thanks a lot :)

anthony_p
Offline
Joined: 2006-07-24

You're welcome.

anthony_p
Offline
Joined: 2006-07-24

The Java Tutorial [1] suggests using the item state listener to track status changes.

[1] http://java.sun.com/docs/books/tutorial/uiswing/components/button.html#c...

heshamg
Offline
Joined: 2008-05-13

Sorry, i should have been more specific.
The problem is i use a JTable with a boolean column inside it, so there is no itemStateChanged event here, so i use MouseClicked() event.

anthony_p
Offline
Joined: 2006-07-24

Then you need to use a table model listener for that as described at [1].

[1] http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#mo...

heshamg
Offline
Joined: 2008-05-13

Thanks Anthony ... Sometimes i set the checkBox value manually so the stateChanged event is executed causing me some problems, but i will try to fix this out.

anthony_p
Offline
Joined: 2006-07-24

1. I think you need to familiarize yourself with the JTable tutorial [1] a bit more deeply. The table model is responsible for storing and manipulating the data displayed in the table, as well as tracking the changes to the data. You almost never need to change the state of a checkbox embedded in a JTable, nor need you access the chekbox directly at all.

2. Speaking of a standalone (not embedded in a table) checkbox, please see [2]. The JCheckBox.setSelected() method does not generate an action event, and therefore should not interfere with listeners installed on the checkbox.

Hope this helps.

[1] http://java.sun.com/docs/books/tutorial/uiswing/components/table.html

[2] http://java.sun.com/javase/6/docs/api/javax/swing/AbstractButton.html#setSelected(boolean)