static void listDependButtons(final JList list, fL buttons) swing { for (Component c : buttons) if (c instanceof JButton) { final JButton b = cast c; list.addListSelectionListener(new ListSelectionListener { public void valueChanged(ListSelectionEvent e) { b.setEnabled(list.getSelectedIndex() >= 0); } }); b.setEnabled(list.getSelectedIndex() >= 0); } }