0

Ive don everything using this guide http://www.cordinc.com/blog/2010/01/jbuttons-in-a-jtable.html

So one little problem remains. While when i click on the button event is fired and method is executed. The buttons animation does not work providing no visual feedback. Im guessing its due to fact that in order to repaint JTable you need to call the models fireTableDataChanged() method.

mKorbel
  • 109,525
  • 20
  • 134
  • 319
user1633277
  • 510
  • 2
  • 7
  • 14
  • The code is in the article I linked . Animation of button press doesnt work there. – user1633277 Feb 05 '13 at 19:40
  • 2
    The problem your actually having is related to the fact that the example your using never actually "clicks" the button, it cheats, and IMHO, badly. Tables use "rubber stamp" approach to rendering its cell contents, that is, the contents aren't actual components, but simply painted facades on them, they have no life of there own. – MadProgrammer Feb 05 '13 at 19:43
  • Is there a way to make them actual components ? – user1633277 Feb 05 '13 at 19:52
  • 1
    Yes, implement `TableCellEditor`, as shown [here](http://docs.oracle.com/javase/tutorial/uiswing/components/table.html#editor). – trashgod Feb 05 '13 at 19:54

2 Answers2

3

Table Button Column shows another way to do this.

camickr
  • 321,443
  • 19
  • 166
  • 288
  • This is the more flexible solution; there's a related example [here](http://stackoverflow.com/a/5559747/230513). – trashgod Feb 06 '13 at 01:00
3

The example cited is less than satisfactory because TableCellRenderer shows a JButton, but the MouseListener ignores the button's ButtonModel. Implementing TableCellEditor, as shown here, is a the better approach. For animation convenience, you may want to look at the DefaultCellEditor, shown here, with a JComboBox having a single entry.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045