更新JTable [英] Updating JTable

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

问题描述

我有点困惑.我正在尝试更新JTable,但是没有更新.这是我目前的代码:

I have little confusion. I am trying to update JTable, but the updates are not coming up. This is my present code:

private void addTable(){

        table = new JTable();// the table for 'Benchmark' tab
        table.setShowVerticalLines(false);
        table.setBorder(null);  

        data = new Object[][] {
                {"Key", ""},//result[0]
                {"Precision", ""},//result[2]+" %"
                {"Cipher", ""},//result[4]
                {"Language", ""},
                {"Performance", ""},//result[3]
        };


        String [] header = new String[] {"Subject of Interest", "Output"};
        model = new DefaultTableModel(data, header);        

        table.setModel(model);


        table.getColumnModel().getColumn(0).setPreferredWidth(136);
        table.getColumnModel().getColumn(1).setPreferredWidth(550);
        GroupLayout gl_panelBenchmark = new GroupLayout(panelBenchmark);
        gl_panelBenchmark.setHorizontalGroup(
                gl_panelBenchmark.createParallelGroup(Alignment.TRAILING)
                .addComponent(textInfoCrypto, GroupLayout.DEFAULT_SIZE, 759, Short.MAX_VALUE)
                .addGroup(gl_panelBenchmark.createSequentialGroup()
                        .addGap(10)
                        .addComponent(textPane, GroupLayout.DEFAULT_SIZE, 739, Short.MAX_VALUE)
                        .addGap(10))
                        .addGroup(Alignment.LEADING, gl_panelBenchmark.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(table, GroupLayout.DEFAULT_SIZE, 739, Short.MAX_VALUE)
                                .addContainerGap())
                );
        gl_panelBenchmark.setVerticalGroup(
                gl_panelBenchmark.createParallelGroup(Alignment.LEADING)
                .addGroup(gl_panelBenchmark.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(textInfoCrypto)
                        .addPreferredGap(ComponentPlacement.UNRELATED)
                        .addComponent(textPane, GroupLayout.PREFERRED_SIZE, 41, GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(ComponentPlacement.UNRELATED)
                        .addComponent(table, GroupLayout.PREFERRED_SIZE, 79, Short.MAX_VALUE)
                        .addContainerGap())
                );
        panelBenchmark.setLayout(gl_panelBenchmark);

    }

这就是我现阶段要更新的一行的方式.下面的代码已从另一种方法调用:

And this is how I am trying to update, at this stage, a single row. The below code has been invoked from another method:

data[0][0]= result[0];
model.fireTableCellUpdated(0, 0);

在此阶段,我只能看到包含行名的表框架,而没有数据.有什么帮助吗?

At this stage I can see only the table frames including row names, but no data. Any help, please?

推荐答案

data只是表模型中未包含的本地数据.您需要使用:

data is only local data not contained in the table model. You need to use:

tableModel.setValue(result [0],0,0);

这篇关于更新JTable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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