| 285 | |
| 286 | // 移除选中的行 |
| 287 | private static void removeSelectedRows(JTable table,DefaultTableModel tableModel) { |
| 288 | int[] selectedRows = table.getSelectedRows(); |
| 289 | if (selectedRows.length > 0) { |
| 290 | int result = JOptionPane.showConfirmDialog(table, "Are you sure you want to remove the selected rows?", |
| 291 | "Confirm Remove", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); |
| 292 | if (result == JOptionPane.YES_OPTION) { |
| 293 | for (int i = selectedRows.length - 1; i >= 0; i--) { |
| 294 | tableModel.removeRow(selectedRows[i]); |
| 295 | } |
| 296 | } |
| 297 | } else { |
| 298 | JOptionPane.showMessageDialog(table, "Please select at least one row to remove.", |
| 299 | "No Rows Selected", JOptionPane.WARNING_MESSAGE); |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | |
| 304 | } |