1 | if (table↵ | | 1 | if (tableModel.getRowCount() > 0) {↵
|
| | | 2 | // If a table cell is being edited, we must cancel the editing↵
|
| | | 3 | // before deleting the row.↵
|
2 | .isEditing()) {↵ | | 4 | if (cookieTable.isEditing()) {↵
|
3 | TableCellEditor cellEditor = table.getCellEditor(table.getEditingRow(), t↵ | | 5 | TableCellEditor cellEditor = cookieTable.getCellEditor(cookieTable.getEditingRow(),↵
|
4 | able.getEditingColumn());↵ | | 6 | cookieTable.getEditingColumn());↵
|
5 | cellEditor.cancelCellEditing();↵ | | 7 | cellEditor.cancelCellEditing();↵
|
6 | }↵ | | 8 | }↵
|
|
7 | int rowSelected = table.getSelectedRow();↵ | | 9 | int rowSelected = cookieTable.getSelectedRow();↵
|
|
8 | if (rowSelected >= 0) {↵ | | 10 | if (rowSelected != -1) {↵
|
9 | tableModel.removeRow(rowSelected);↵ | | 11 | tableModel.removeRow(rowSelected);↵
|
10 | tableModel.fireTableDataChanged();↵ | | 12 | tableModel.fireTableDataChanged();↵
|
|
11 | // Disable DELETE if there are no rows in the table to↵ | | 13 | // Disable the DELETE and SAVE buttons if no rows remaining↵
|
12 | delete.↵ | | 14 | // after delete.↵
|
13 | if (tableModel.getRowCount() == 0) {↵ | | 15 | if (tableModel.getRowCount() == 0) {↵
|
14 | delete.setEnabled(false);↵ | | 16 | deleteButton.setEnabled(false);↵
|
15 | ↵ | | 17 | saveButton.setEnabled(false);↵
|
16 | }↵ | | 18 | }↵
|
|
17 | // Table still contains one or more rows, so highlight↵ | | 19 | // Table still contains one or more rows, so highlight↵
|
18 | (select)↵ | | 20 | // (select)↵
|
19 | // the appropriate one.↵ | | 21 | the appropriate one.↵
|
20 | else {↵ | | 22 | else {↵
|
21 | int rowToSelect = rowSelected;↵ | | 23 | int rowToSelect = rowSelected;↵
|
|
22 | if (rowSelected >= tableModel.getRowCount()) {↵ | | 24 | if (rowSelected >= tableModel.getRowCount()) {↵
|
23 | rowToSelect = rowSelected - 1;↵ | | 25 | rowToSelect = rowSelected - 1;↵
|
24 | }↵ | | 26 | }↵
|
|
25 | table.setRowSelectionInterval(rowToSelect, rowToSelect);↵ | | 27 | cookieTable.setRowSelectionInterval(rowToSelect, rowToSelect);↵
|
26 | }↵ | | 28 | }↵
|
27 | ↵ | | 29 | }↵
|
28 | } | | 30 | }
|