code: public void valueChanged(ListSelectionEvent lse) {
          int selectedIndex = list.getSelectedIndex();
          if (selectedIndex == -1) {
              editButton.setEnabled(false);
              removeButton.setEnabled(false);
              moveUpButton.setEnabled(false);
              moveDownButton.setEnabled(false);
              return;
          }
  
          editButton.setEnabled(true);
          removeButton.setEnabled(true);
          moveUpButton.setEnabled(selectedIndex != 0);
          moveDownButton.setEnabled(selectedIndex != list.getLastVisibleIndex());
      }
docs: implement ListSelectionListener