空のテーブルを作成しました:
String columnNames[] = {"br", "artikal", "cena", "kolicina","ukupno" };
String dataValues[][] =new String[10][5];
DefaultTableModel tableModel=new DefaultTableModel(dataValues, columnNames);
そして、ループによって最初の行から最後の行まで順番に1つの列を埋めたいとします。
if ((((JButton)e.getSource()).getText()).equals(name.getName())){
for (int i=0;i<10;i++){
String products= (String) bill.tableModel.getValueAt(i, 1);
String p=Double.toString(name.getPrice());
if(products.equals(""))
bill.tableModel.setValueAt(name.getName(),i, 1);
bill.tableModel.setValueAt(p,i, 2);
break;
}
}
ボタンをクリックすると何も表示されませんが、if条件を削除するとif (products.equals(""))
機能しますが、空の列のセルを埋める代わりに、列の最初のセルにテキストをもう一度設定します。
試し てみましたがif ( dataValues[i][1].equals("null"))
、if (products.equals("null"))
何も表示されません。コンソールにSystem.out.print((String) bill.tableModel.getValueAt(0, 1))
「null」を表示すると。
列のセルを埋める他の方法はありますか?