在上表中有在由序列號表示的表4的值(S.NO 1,2,3,4)
的問題是,當我們從表中刪除的行狀S.NO 2
然後使用removeRow方法刪除一行但不調整S.No S.NO的代碼就像我引入一個名爲tree的int變量,當我們按下add按鈕時它會在樹中添加一個值
int tree=0;
,當我們按添加按鈕
tree++;
,我也嘗試
.getRowCount()
得到行號就可以獲得它和打印,也而T3再次母雞當我們刪除一行,並添加另一排它只是打印該行number.So如何調整S.No
添加按鈕(用於添加表以及在數據庫數據)
class google{
int tree=0;
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { //add Button method
model=(DefaultTableModel) mtt.getModel(); //mtt name of table
tree++; //increment S.No
model.addRow(new Object[]{tree,proname.getText(),TFroo.getText(),qty.getText(),total.getText(),bn.getText()}); // getting text from text field and add it in table
// and some other code to add data on database
}//Add Button ActionPerformed
}//google
準則
刪除按鈕的代碼
int p= JOptionPane.showConfirmDialog(null,"SURE YOU WANT TO DELETE ?","CONFORM",JOptionPane.YES_NO_OPTION);
if(p==JOptionPane.YES_OPTION)
{
model.removeRow(mtt.getSelectedRow());
// and some other code to delete data also form database
}
感謝回覆:) –
我添加代碼的添加按鈕和刪除按鈕看看 –
@NeerajSharma,完成! –