如何不在 JTable 中添加行?

问题描述

现在我正在做一个记录订单的项目。当数量栏的值变为零时,应该不记录购买。但是,当我尝试创建一个条件语句时,当数量的值为零时,它不会向另一个表中添加一行。

这是我尝试让它工作的尝试

try {
    float price = Float.parseFloat(PTF.getText());
    int quan = Integer.parseInt(QTF.getText());

    String tottal = String.valueOf(price * quan);

    AmountTF.setText(tottal);

    DefaultTableModel model = (DefaultTableModel)RecTable.getModel();
    model.addRow(new Object[] {QTF.getText(),PTF.getText(),BrandNTF.getText(),AmountTF.getText(),FNameTF.getText(),dateForm.format(obj)});  
    int z = 0;
    int i = ProdTable.getSelectedRow();
    int x = Integer.parseInt(QTF.getText());                    
    String MINUS = ProdTable.getModel().getValueAt(i,5).toString();
    int update=Integer.parseInt(MINUS);
    int y=update-x;
    DefaultTableModel model1 = (DefaultTableModel)ProdTable.getModel();
    model1.setValueAt(y,i,5);

    if (update < x) {
        QTF.setText(" ");
        model.removeRow(y);
        model1.setValueAt(0,5);
        JOptionPane.showMessageDialog(AddB,"No more items");
    }
} catch (Exception c) {
    JOptionPane.showMessageDialog(null,"Missing Credentials");
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)