user4205580
user4205580

Reputation: 572

JTable cell editor doesn't work when set using setCellEditor method

There's a problem I'm having with getting the cell editor to work with my JTable.

I instantiated the JTable in the usual way (the JTable contains empty rows and columns):

table = new JTable(new DefaultTableModel(4,4));

and then wanted to see if a cell editor can work with it using the example from Oracle tutorials.

Surprisingly it works only if I set it for every column separately (first line below), but I'm unable to set it for the whole table (second line).

table.getColumnModel().getColumn(0).setCellEditor(new ColorEditor());       
table.setCellEditor(new ColorEditor());

Any ideas why this might be the case?

Upvotes: 1

Views: 661

Answers (1)

trashgod
trashgod

Reputation: 205785

Note that TableDialogEditDemo uses setDefaultEditor(), which will evoke the ColorEditor for all cells whose type is Color.class.

table.setDefaultEditor(Color.class, new ColorEditor());

The table will invoke setCellEditor() for you when you edit a cell.

Upvotes: 2

Related Questions