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 | // removeProperty(tableModel.getValueAt (↵ | | 11 | ↵
|
10 | // table.getSelectedRow(),0).toString());↵ | | |
|
11 | tableModel.removeRow(rowSelected);↵ | | 12 | tableModel.removeRow(rowSelected);↵
|
12 | tableModel.fireTableDataChanged();↵ | | 13 | tableModel.fireTableDataChanged();↵
|
|
13 | // Disable DELETE if there are no rows in the table to↵ | | 14 | // Disable the DELETE and SAVE buttons if no rows remaining↵
|
14 | delete.↵ | | 15 | // after delete.↵
|
15 | if (tableModel.getRowCount() == 0) {↵ | | 16 | if (tableModel.getRowCount() == 0) {↵
|
16 | delete.setEnabled(false);↵ | | 17 | deleteButton.setEnabled(false);↵
|
17 | } else {↵ | | 18 | saveButton.setEnabled(false);↵
|
| | | 19 | }↵
|
|
18 | // Table still contains one or more rows, so highlight↵ | | 20 | // Table still contains one or more rows, so highlight↵
|
19 | (select)↵ | | 21 | // (select)↵
|
20 | // the appropriate one.↵ | | 22 | the appropriate one.↵
|
21 | ↵ | | 23 | else {↵
|
22 | int rowToSelect = rowSelected;↵ | | 24 | int rowToSelect = rowSelected;↵
|
|
23 | if (rowSelected >= tableModel.getRowCount()) {↵ | | 25 | if (rowSelected >= tableModel.getRowCount()) {↵
|
24 | rowToSelect = rowSelected - 1;↵ | | 26 | rowToSelect = rowSelected - 1;↵
|
25 | }↵ | | 27 | }↵
|
|
26 | table.setRowSelectionInterval(rowToSelect, rowToSelect);↵ | | 28 | cookieTable.setRowSelectionInterval(rowToSelect, rowToSelect);↵
|
27 | }↵ | | 29 | }↵
|
28 | ↵ | | 30 | }↵
|
29 | } | | 31 | }
|