• Post Reply Bookmark Topic Watch Topic
  • New Topic

Table with JCheckBox

 
David Garratt
Ranch Hand
Posts: 213
Eclipse IDE Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to get a checkbox within a table to fire an event when it's clicked rather. I gave tried putting in a TableModelListener but the the event only seems to trigger when I click on another column (as if the table is waiting to see if I will change my mind) before moving on.

I have also looked at the setValue of the TableModel itself.

Do I need to put an ActionListener on each checkbox or have I missed something ?

Thanks in advance

Dave
 
Rob Camick
Ranch Hand
Posts: 2699
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I gave tried putting in a TableModelListener


That is the correct approach.

As long as you store Boolean data in the TableMode and you override the getColumnClass(...) method of your TableModel to return Boolean.class and you override the isCellEditable(...) method for the column then the TableModelListener should fire the proper event.

If you need more help then post a SSCCE demonstrating the problem.
 
David Garratt
Ranch Hand
Posts: 213
Eclipse IDE Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for you reply. I am in the process of creating a cut down version of the source which illustrates my problem.

Imagine a table with several columns, say 8 for example. Each column has a checkbox. If none of them are selected and I click the 1st column I don't see the event for that column. If I then click column 2 I see the change for column 1 and so on.

I suppose if you were to think of them as edit box's you would not want to see change events when you type, only when you exit the field.

However in my case I want to see some form of event which I can capture on the value change of the checkbox - immediately.

I will persevere with my demo code for now.

Dave
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!