[英]How to Make empty row editable in JXTable
我有一個鏈接到MySQL數據庫的jXTable。 我正在使用DefaultTableModel。 到目前為止,我可以讓用戶編輯表中的數據。 我一直在嘗試添加“插入新行”按鈕,但未成功。 同時,我認為我可以在每次用戶更新表時在表末尾添加一個空行。 我可以使用addRow()方法獲取空行,但是它不可編輯。 到目前為止,這是我的代碼。 關於如何使空行可編輯的任何提示?
public void rowSetChanged(RowSetEvent event) {
Object[] record;
Object[] emptyrow;
String [] columnNames=new String [] {"DATE RECEIVED", "INCOME NAME",
"DESCRIPTION", "AMOUNT", "FUND ALLOCATION"};
DefaultTableModel dtm=new DefaultTableModel(columnNames,0){
Class[] types = new Class [] {
java.sql.Date.class, java.lang.String.class, java.lang.String.class,
java.lang.Object.class, java.lang.Float.class, java.lang.String.class};
public Class getColumnClass(int columnIndex) {
return types [columnIndex];
}
};
try {
IncomeUI.frs.beforeFirst();
while (IncomeUI.frs.next()){
record=new Object[]{IncomeUI.frs.getDate("DateReceived"),
IncomeUI.frs.getString("IncomeName"), IncomeUI.frs.getString("Description"),
IncomeUI.frs.getBigDecimal("Amount"),IncomeUI.frs.getString("FundAllocation")};
dtm.addRow(record);
}
} catch (SQLException ex) {ex.printStackTrace();}
emptyrow = new Object[]{" ", " ", " ", " ", " "};
dtm.addRow(emptyrow);
this.setModel(dtm);
this.setShowHorizontalLines(false);
this.setShowVerticalLines(false);
IncomeUI.jScrollPane2.setViewportView(this);
//System.out.println(event.toString());
}
好吧,不是100%修復,但是可以。 我最終只是添加代碼以添加帶有偽數據的新行(例如“ Edit Me”)。 用戶可以重新編輯它。 現在可以使用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.