1

我已经使用了 fireDataChanged 方法,但我认为由于它连接到我的数据库,它不会做任何事情。

    DelBtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            int selRow = table.getSelectedRow();            
            Object element = table.getValueAt(selRow, 0);
            th = table.getTableHeader();
            tcm = th.getColumnModel();
            Statement statement = null;
            try {
                statement = ResultSetTableModelFactory.connection
                        .createStatement();


                    if (JisSelected == true) {

                        String delete = "DELETE FROM J WHERE JNO = '" + element + "';";
                        statement.executeUpdate(delete);
                    }
                     if (SPJisSelected == true) {

                        String delete = "DELETE FROM SPJ WHERE SNO = '" + element + "';";
                        statement.executeUpdate(delete);

                    }
                System.out.println(element);
            } catch (Exception ex) {
                //ex.printStackTrace();
            }
            model.fireTableDataChanged();
        }
    });

}
4

1 回答 1

2

您应该在实现a 的方法时ActionListener执行其工作。在此期间,您应该以适合您的应用程序的任何方式表明该操作处于挂起状态,可能是在渲染器或状态指示器中。如果数据库操作成功,请更新您的. 在任何情况下,您都不应从模型内部调用。doInBbackground()SwingWorkerTableModeldone()fireTableDataChanged()

于 2013-11-08T16:17:42.360 回答