我已经声明了一个 JTable(在类扩展 JPanel 构造函数内),例如
data_table = new JTable(info, header) {
@Override
public boolean isCellEditable(int row, int column) {
//disable table editing
return false;
}
};
声明信息和列的位置
static String[][] info = new String[row][cols];
static String[] header = {"h1", "h2", "h3"};
现在我需要在发生某些事件时通过调用静态方法来更新表内容。我该怎么做?
最佳答案
i don't have a tableModel, i've a matrix of string
所有表都使用 TableModel。创建表时,TableModel 使用字符串矩阵。
要更新您的数据,您可以执行以下操作:
table.setValueAt(...);
这将导致模型更新,并且模型将告诉表格重新绘制自身。
阅读 How to Use Tables 上的 Swing 教程有关表格的更多信息。
此外,您不应该使用静态变量或方法。如果你是这样,那么你的程序设计得很糟糕。再次阅读本教程,了解如何构建代码的更好示例。
关于java - JTable,在静态上下文中刷新 rowData vector ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17702653/