简体   繁体   English

如何在Java中的GlazedLists / JTable中使列,行或单元格可编辑?

[英]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? 任何人都可以放一行代码来显示如何使GlazdJTable的单元格可编辑吗?

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. 注意:我知道TableFormat必须实现WritableTableFormat接口。 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. 但我不知道我应该创建自定义表格格式,还是可以像设置JTable一样将Jtable单元格设置为可编辑状态。

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

The recommended way is to use a WritableTableFormat . 推荐的方法是使用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 ). EventTableModel检查表格式是否为WritableTableFormat,如果是,则将isEditable()问题委托给它(如EventTableModel docs中所述 )。 Otherwise EventTableModel assumes the table is not editable. 否则,EventTableModel假定该表不可编辑。

At the moment you're using the GlazedLists.tableFormat() convenience method rather than instantiating your own TableFormat. 目前,您正在使用GlazedLists.tableFormat()便捷方法,而不是实例化自己的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 . 请参阅GlazedLists.tableFormat(String [] propertyNames,String [] columnLabels,boolean [] editable)文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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