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

The following examples show how to use javax.swing.DefaultListModel#insertElementAt() . 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: CodeCompletionPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void javaCompletionExcluderDialogOkButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_javaCompletionExcluderDialogOkButtonActionPerformed
    JList list = getSelectedExcluderList();
    String text = javaCompletionExcluderDialogTextField.getText();
    DefaultListModel model = (DefaultListModel) list.getModel();
    int index = model.size();
    if (javaExcluderEditing != null){
        // if this was an "edit" rather than "add", then remove the old entry first
        index = model.indexOf(javaExcluderEditing);
        model.remove(index);
        javaExcluderEditing = null;
    }
    String[] entries = text.split(","); // NOI18N
    for (String entry : entries) {
        // strip zero width spaces
        entry = entry.replaceAll("\u200B", "");  // NOI18N
        entry = entry.trim();
        if (entry.length() != 0 && entry.matches(JAVA_FQN_REGEX)){
            model.insertElementAt(entry, index);
            index++;
        }
    }
    updateExcluder(list);
    javaCompletionExcluderDialog2.setVisible(false);
    javaCompletionExcluderDialogTextField.setText(null);
}
 
Example 4
Source File: SystemPanel.java    From megamek with GNU General Public License v2.0 6 votes vote down vote up
private void displayLocations() {
    DefaultListModel<String> locModel = ((DefaultListModel<String>) locList
            .getModel());
    locModel.removeAllElements();
    locModel.insertElementAt(
            Messages.getString("MechDisplay.AllEquipment"), LOC_ALL_EQUIP);
    locModel.insertElementAt(
            Messages.getString("MechDisplay.AllWeapons"), LOC_ALL_WEAPS);
    locModel.insertElementAt("-----", LOC_SPACER);
    for (int loc = 0; loc < en.locations(); loc++) {
        int idx = loc + LOC_OFFSET;
        if (en.getNumberOfCriticals(loc) > 0) {
            locModel.insertElementAt(en.getLocationName(loc), idx);
        }
    }
    locList.setSelectedIndex(0);
    displaySlots();
}
 
Example 5
Source File: DescriptionInfoTab.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
private NoteInfoPane createNotePane(NoteItem note, CharacterFacade character,
	DefaultListModel<PageItem> listModel, List<NoteInfoPane> notePaneList, int pos)
{
	NoteInfoPane notePane = new NoteInfoPane(note);
	PageItem pageItem = new PageItem(character, note, notePane);
	if (pos >= 0 && pos < notePaneList.size())
	{
		// List model also has the portrait etc tabs, so we have to skip over those.
		listModel.insertElementAt(pageItem, pos + NUM_NON_NOTE_NODES);
		notePaneList.add(pos, notePane);
	}
	else
	{
		listModel.addElement(pageItem);
		notePaneList.add(notePane);
	}
	return notePane;
}
 
Example 6
Source File: DescriptionInfoTab.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
private NoteInfoPane createNotePane(NoteItem note, CharacterFacade character,
	DefaultListModel<PageItem> listModel, List<NoteInfoPane> notePaneList, int pos)
{
	NoteInfoPane notePane = new NoteInfoPane(note);
	PageItem pageItem = new PageItem(character, note, notePane);
	if (pos >= 0 && pos < notePaneList.size())
	{
		// List model also has the portrait etc tabs, so we have to skip over those.
		listModel.insertElementAt(pageItem, pos + NUM_NON_NOTE_NODES);
		notePaneList.add(pos, notePane);
	}
	else
	{
		listModel.addElement(pageItem);
		notePaneList.add(notePane);
	}
	return notePane;
}
 
Example 7
Source File: CategoryPanelFormatters.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void formattersMoveDownButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_formattersMoveDownButtonActionPerformed
    int index = formattersList.getSelectedIndex();
    if (index < 0) return ;
    DefaultListModel model = (DefaultListModel) formattersList.getModel();
    if (index >= (model.getSize() - 1)) return ;
    Object obj = model.remove(index);
    model.insertElementAt(obj, index + 1);
    formattersList.setSelectedIndex(index + 1);
}