Pregunta

Can any one drop a line of code to show how to make a GlazdJTable's cell editable?

JTable table = new Jtable();
    TableFormat tableFormat = GlazedLists.tableFormat(properties, headers);
    model = new EventTableModel<Artikel>(filterList, tableFormat);
    selectionModel = new EventSelectionModel<Artikel>(filterList);

    table.setSelectionModel(selectionModel);
    table.setModel(model);

// how to set table cell editable?

Note: I know that TableFormat must implement the WritableTableFormat interface. but i don't know should i create a custom table format or it is possble to set the Jtable cell editable just like a JTable.

¿Fue útil?

Solución

The recommended way is to use a WritableTableFormat. The EventTableModel checks to see whether the table format is a WritableTableFormat and if so delegates the isEditable() question to that (as described in the EventTableModel docs). Otherwise EventTableModel assumes the table is not editable.

At the moment you're using the GlazedLists.tableFormat() convenience method rather than instantiating your own TableFormat. That's fine, there is a method precisely for this case where you specify whether each column is editable by passing in an array of booleans. See the GlazedLists.tableFormat(String[] propertyNames, String[] columnLabels, boolean[] editable) documentation.

Otros consejos

Override TableModel's method public boolean isCellEditable(int rowIndex, int columnIndex) to return true for editable and false for the rest cells.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top