給妳的jtable添加壹個MouseListener
在實現MouseListener 的類中有壹個方法 以下代碼是我原來做的妳可以參考以下
public void mousePressed(MouseEvent e)
{
if (e.getClickCount() >= 2)
{
int row = dataTable.rowAtPoint(e.getPoint());
int column = dataTable.columnAtPoint(e.getPoint());
if (column == 4)// 顯示remark 字段
{
JOptionPane.showMessageDialog(this, dataTable.getValueAt(row, column), "備註詳細", 1);
}
else if (column == 5)// 詢問是否刪除
{
String date = (String) dataTable.getValueAt(row, 0);
String type1 = (String) dataTable.getValueAt(row, 1);
String type2 = (String) dataTable.getValueAt(row, 2);
String fee = (String) dataTable.getValueAt(row, 3);
String remark = (String) dataTable.getValueAt(row, 4);
String idKey = (String) dataTable.getValueAt(row, 5);
String info = date + "\n" + type1 + "\n" + type2 + "\n" + fee + "\n" + remark;
int confirm = JOptionPane.showConfirmDialog(this, info, "是否刪除?",
JOptionPane.YES_NO_OPTION);
if (confirm == 0)
{
try
{
AccountService.delete(date, idKey);
if (date == null || "".equals(date))
{
date = Util.getToday();
}
list = AccountService.getOneDayInfo(date);
dataScrollPane.setViewportView(getDataTable(list));
}
catch (Exception e1)
{
JOptionPane.showMessageDialog(this, "刪除異常");
}
}
}
}
}