static void tableDependButtons(JTable table, L buttons) { for (Component c : buttons) if (c instanceof JButton) swing { JButton b = cast c; table.getSelectionModel().addListSelectionListener(e -> swingLater(-> { // Using swingLater helps us avoid loss of selection during table updates b.setEnabled(table.getSelectedRow() >= 0); })); b.setEnabled(table.getSelectedRow() >= 0); } }