Java Code Examples for javax.swing.DefaultListModel#removeElementAt()

The following examples show how to use javax.swing.DefaultListModel#removeElementAt() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StringSetPropertyEditorPanel.java    From openAGV with Apache License 2.0 6 votes vote down vote up
/**
 * Bewegt den aktuellen Eintrag nach unten.
 *
 * @param evt das auslösende Ereignis
 */
private void moveDownButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_moveDownButtonActionPerformed
  int index = itemsList.getSelectedIndex();

  if (index == -1) {
    return;
  }

  DefaultListModel<String> model = (DefaultListModel<String>) itemsList.getModel();

  if (index == model.size() - 1) {
    return;
  }

  String value = model.getElementAt(index);
  model.removeElementAt(index);
  model.insertElementAt(value, index + 1);
  itemsList.setSelectedIndex(index + 1);
}
 
Example 2
Source File: StringSetPropertyEditorPanel.java    From openAGV with Apache License 2.0 6 votes vote down vote up
private void moveUpButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_moveUpButtonActionPerformed
  int index = itemsList.getSelectedIndex();

  if (index == -1) {
    return;
  }

  if (index == 0) {
    return;
  }

  DefaultListModel<String> model = (DefaultListModel<String>) itemsList.getModel();
  String value = model.getElementAt(index);
  model.removeElementAt(index);
  model.insertElementAt(value, index - 1);
  itemsList.setSelectedIndex(index - 1);
}
 
Example 3
Source File: FolderList.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void exportDone(JComponent comp, Transferable trans, int action) {
    if (action == MOVE) {
        final JList from = (JList) comp;
        final DefaultListModel model = (DefaultListModel) from.getModel();
        for (int i=indices.length-1; i>=0; i--) {
            model.removeElementAt(indices[i]);
        }
    }
}