如何将数据添加到Java Swing表格中的新行?

huangapple go评论76阅读模式
英文:

How do you add data to a new row in a java swing table?

问题

我已经使用以下代码创建了一个新的表格行,但是我在向该行填充数据时遇到了问题。有什么方法可以向新的表格行添加数据呢?

    DefaultTableModel model = (DefaultTableModel) this.jTable1.getModel();
    Object[] row = new Object[4];
英文:

I have created a new table row with the below code, however I am having trouble populating that row with data. How would one go about adding data to the new table row?

    DefaultTableModel model = (DefaultTableModel) this.jTable1.getModel();
    Object[] row = new Object[4];

答案1

得分: 0

得到外部帮助 - 这里是为了后人记录的解决方案;

DefaultTableModel model = (DefaultTableModel)
this.jTable1.getModel();
Object[] row = new Object[4];
row[0] = newUser;
row[1] = newPass;
row[2] = newDept;
row[3] = newTel;

model.addRow(row);

注意:将变量替换为您所需的内容。

英文:

Got outside help - here's the solution for posterity;

        DefaultTableModel model = (DefaultTableModel)
        this.jTable1.getModel();     
        Object[] row = new Object[4];
        row[0] = newUser;
        row[1] = newPass;
        row[2] = newDept;
        row[3] = newTel;

        model.addRow(row);

Note: Replace variables with what you want.

huangapple
  • 本文由 发表于 2020年9月14日 12:23:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/63878082.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定