JTable,在静态上下文中刷新rowData向量 [英] JTable, refreshing rowData vector in static context

查看:95
本文介绍了JTable,在静态上下文中刷新rowData向量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经声明了一个JTable(在类扩展的JPanel构造函数内部),例如

i've declared a JTable (inside a class extended JPanel constructor) such as

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"};

现在,当某些事件发生时,我需要通过调用静态方法来更新表内容.我该怎么办?

Now i need to update, when some events occours, the table content by invoke a static method. How can i do it?

推荐答案

我没有tableModel,我有一个字符串矩阵

i don't have a tableModel, i've a matrix of string

所有表都使用TableModel.创建表时,TableModel使用字符串矩阵.

All tables use a TableModel. When you create the table the matrix of Strings is used by the TableModel.

要更新数据,您可以执行以下操作:

To update your data you do something like:

table.setValueAt(...);

这将导致模型被更新,并且模型将告诉表重新绘制自身.

This will cause the model to be updated and the model will tell the table to repaint itself.

如何使用表上阅读Swing教程有关表的更多信息.

Read the Swing tutorial on How to Use Tables for more information about tables.

此外,您不应该使用静态变量或方法.如果您是,那么您的程序设计不佳.再次阅读该教程,以获取有关如何构建代码的更好示例.

Also, you should NOT be using static variables or method. If you are then you program is poorly designed. Again read the tutorial for a better example of how to structure your code.

这篇关于JTable,在静态上下文中刷新rowData向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆