简体   繁体   中英

How to make a column, row or cell editable in a GlazedLists/JTable in java?

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.

重写TableModel's方法public boolean isCellEditable(int rowIndex, int columnIndex)以对可编辑返回true,对其余单元格返回false。

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM