views:

20

answers:

1

Hi,

i'm trying to edit the content of the cells of a certain column in my JTable with ComboBoxes. Therefore i simply use the code from the official Java Tutorial on JTables (http://download.oracle.com/javase/tutorial/uiswing/components/table.html). The relevant code ends up looking like this:

tableModel = new NetworkTableModel(columnNames,0,0);
networkTable = new JTable(tableModel);
....
TableColumn sendingColumn = networkTable.getColumnModel().getColumn(3);  
JComboBox sendingBox = new JComboBox();
sendingBox.addItem("Sending");
sendingBox.addItem("Receiving");
sendingColumn.setCellEditor(new DefaultCellEditor(sendingBox));

The Problem is when i click on a cell in that column the ComboBox doesn't appear. I am perfectly able to edit the cells but only by typing into them. Why is the ComboBox not showing up?

A: 

Problem Solved.

Unexperienced as I am, i did always set a complete new table model for my table when the underlying data changed (more precise the number of objects representing a row in the table). thats why the combo boxes didn't show up for all but the first instance of the table model i created, because i only called the setCellEditor method on this instance. Changed my program to not always creating a new table model and everything works fine now....learned something.

dennisg