在 Java 中创建 TableColumn 并将其添加到 JTable
Creating a TableColumn in Java and adding it to a JTable
我有一个现有的 Jtable,里面有数据。我想创建一个包含自定义数据的新列并将其添加到 table。我可以创建一个新列作为 TableColumn tc = new TableColumn();
并将其添加到 table 作为 table.addColumn(tc)
。但我想不出一种方法来设置新列中单元格的值。创建 table 列后是否可以手动设置单元格的值?
I can create a new column...
首先您需要指定此TableColumn 代表TableModel 中的哪一列。例如:
tableColumn tc = new TableColumn(3)
table.addColumn(tc):
Is it possible to manually set the values of the cells after I created a table column?
那么你可以使用:
table.setValueAt("hello", 0, 3);
设置第一行的值。
最简单的方法是使用 DefaultTableModel
的 addColumn(...)
方法。它允许您添加一个空列或包含数据的列。
我有一个现有的 Jtable,里面有数据。我想创建一个包含自定义数据的新列并将其添加到 table。我可以创建一个新列作为 TableColumn tc = new TableColumn();
并将其添加到 table 作为 table.addColumn(tc)
。但我想不出一种方法来设置新列中单元格的值。创建 table 列后是否可以手动设置单元格的值?
I can create a new column...
首先您需要指定此TableColumn 代表TableModel 中的哪一列。例如:
tableColumn tc = new TableColumn(3)
table.addColumn(tc):
Is it possible to manually set the values of the cells after I created a table column?
那么你可以使用:
table.setValueAt("hello", 0, 3);
设置第一行的值。
最简单的方法是使用 DefaultTableModel
的 addColumn(...)
方法。它允许您添加一个空列或包含数据的列。