gpt4 book ai didi

java - 在 Java 中的默认表模型中添加行

转载 作者:行者123 更新时间:2023-11-30 10:42:39 24 4
gpt4 key购买 nike

我已经使用 jframe 创建了一个包含 3 列的 jtable,现在我正在尝试添加用户通知的特定行数,但是我的表在使用我的添加行方法后它总是空的。

package cpm;

import static java.lang.Integer.parseInt;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;


public class tela extends javax.swing.JFrame {

public tela() {
initComponents();
DefaultTableModel modelo = (DefaultTableModel)jTable1.getModel();
String quantidade = JOptionPane.showInputDialog("Informe a quantidade de atividades");
int qtd = parseInt(quantidade);
for (int i = 0; i == qtd ; i++) {
modelo.addRow(new Object[]{"","",""});
}
jTable1.setModel(modelo);
}



public static void main(String args[]) {

java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new tela().setVisible(true);
}
});
}

// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable jTable1;
private javax.swing.JTextField jTextField1;
// End of variables declaration


}

我使用 Jframe 的图形设计来创建列。

最佳答案

I'm trying to add a specific number of lines informed by the user

使用DefaultTableModelsetRowCount() 方法。

它将添加空行数据,这就是您正在做的事情。

关于java - 在 Java 中的默认表模型中添加行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38031739/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com