问题描述
我只是做了一个按钮,可以添加jComboBox中的产品,jTextField中我们想要的数量以及jTable中产品的价格。
我希望我的按钮添加产品,并且如果它已经在jTable中,它只是将我们想要的数量添加到右列。它适用于我拥有的第一个产品,但不适用于其他产品。
String cp = jComboBoxProduit.getSelectedItem().toString();
//CategorieCombo is a class that gives us the id,value or price of a row in a sql table
CategorieCombo pp = (CategorieCombo) jComboBoxProduit.getSelectedItem();
DefaultTableModel leModel = (DefaultTableModel) jTable4.getModel();
if(jTable4.getRowCount() != 0)
{
for (int i = 0; i < jTable4.getRowCount(); i++)
{
if ((String)jTable4.getValueAt(i,0) != cp)
{
leModel.addRow(new Object[]{cp,jTextFieldQuantity.getText(),pp.getPrix()});
}
else {
int qte = Integer.valueOf(jTable4.getValueAt(i,1).toString());
qte = qte + Integer.valueOf(jTextFieldQuantity.getText());
jTable4.setValueAt(qte,i,1);
}
}
}
else
{
leModel.addRow(new Object[]{cp,pp.getPrice()});
}
我认为这行不通,因为以下一行
leModel.addRow(new Object[]{cp,pp.getPrix()});
它位于for循环中,所以也许它每次在表中有一行时才执行,但是我想是否可以只执行一次该行。
我希望我已经足够清楚了,谢谢您能帮助我找到答案!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)