Java Code Examples for javax.swing.DefaultListModel

The following examples show how to use javax.swing.DefaultListModel. These examples are extracted from open source projects. 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
private void loadRecent() {
    recentModel = new DefaultListModel();
    for (RecentItem recentItem : sMainFrame.getRecentItems().getRECENT_ITEMS()) {
        recentModel.addElement(recentItem);
    }
    recentItems.setModel(recentModel);
    if (recentModel.isEmpty()) {
        recentToggle.setEnabled(false);
        recentToggle.setForeground(Color.GRAY);
        appToggle.setSelected(true);
    } else {
        recentItems.setSelectedIndex(0);
        recentToggle.setSelected(true);
    }

}
 
Example 2
Source Project: attic-polygene-java   Source File: StatePane.java    License: Apache License 2.0 6 votes vote down vote up
StatePane( DetailModelPane detailModelPane )
{
    super( detailModelPane );
    this.setLayout( new BorderLayout() );
    this.add( contentPane, BorderLayout.CENTER );

    methodListModel = new DefaultListModel();
    methodList.setModel( methodListModel );
    methodList.setCellRenderer( new MethodListCellRenderer() );
    methodList.setPrototypeCellValue( "12345678901234567890" );
    methodList.setSelectionMode( ListSelectionModel.SINGLE_SELECTION );

    methodDetailTableModel = new MethodDetailTableModel();
    methodDetailTable.setModel( methodDetailTableModel );

    TableColumnModel columnModel = methodDetailTable.getColumnModel();
    columnModel.getColumn( 0 ).setPreferredWidth( 75 );
    columnModel.getColumn( 1 ).setPreferredWidth( 400 );

    //splitPane.setDividerLocation( .1 );
    methodList.addListSelectionListener( this::methodListValueChanged );
}
 
Example 3
@Override
public void setDataTable(DataTable dataTable) {
	super.setDataTable(dataTable);
	this.dataTable = dataTable;

	// ignore list
	DefaultListModel<String> ignoreModel = (DefaultListModel<String>) ignoreList.getModel();
	ignoreModel.clear();
	for (int i = 0; i < this.dataTable.getNumberOfColumns(); i++) {
		if (i == colorColumn) {
			continue;
		}
		ignoreModel.addElement(this.dataTable.getColumnName(i));
	}

	this.maxWeight = getMaxWeight(dataTable);

	repaint();
}
 
Example 4
private void checkBoxList_FieldsMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_checkBoxList_FieldsMouseClicked
    // TODO add your handling code here:
    DefaultListModel listModel = (DefaultListModel) this.checkBoxList_Fields.getModel();
    int idx = this.checkBoxList_Fields.getSelectedIndex();
    CheckBoxListEntry item = (CheckBoxListEntry) listModel.getElementAt(idx);
    String selFieldStr = item.getValue().toString();
    if (item.isSelected()) {
        PolygonBreak aPB = new PolygonBreak();
        aPB.setCaption(selFieldStr);
        aPB.setTag(selFieldStr);
        aPB.setColor(LegendManage.createRandomColors(1)[0]);
        legendView_Chart.getLegendScheme().getLegendBreaks().add(aPB);
    } else {
        for (int i = 0; i < legendView_Chart.getLegendScheme().getBreakNum(); i++) {
            if (legendView_Chart.getLegendScheme().getLegendBreaks().get(i).getTag().equals(selFieldStr)) {
                legendView_Chart.getLegendScheme().getLegendBreaks().remove(i);
                break;
            }
        }
    }
    this.legendView_Chart.repaint();
}
 
Example 5
private void resetMaskListState() {
    maskNameListModel = new DefaultListModel<>();
    final String[] currentSelectedMaskNames = getSelectedMaskNames();
    if (product != null && raster != null) {
        //todo [multisize_products] compare scenerastertransform (or its successor) rather than size (tf)
        final ProductNodeGroup<Mask> maskGroup = product.getMaskGroup();
        for (int i = 0; i < maskGroup.getNodeCount(); i++) {
            final Mask mask = maskGroup.get(i);
            if (mask.getRasterSize().equals(raster.getRasterSize())) {
                maskNameListModel.addElement(mask.getName());
            }
        }
        maskNameList.setModel(maskNameListModel);
    }
    final String[] allNames = StringUtils.toStringArray(maskNameListModel.toArray());
    indexesInMaskNameList = new int[allNames.length];
    for (int i = 0; i < allNames.length; i++) {
        String name = allNames[i];
        if (StringUtils.contains(currentSelectedMaskNames, name)) {
            maskNameList.getCheckBoxListSelectionModel().addSelectionInterval(i, i);
        }
        indexesInMaskNameList[i] = i;
    }
    updateEnablement();
}
 
Example 6
private void initialize() {
    this.setTitle("Meteo Data");
    this.jList_DataFiles.setModel(new DefaultListModel());
    this.jComboBox_Variable.removeAllItems();
    this.jComboBox_Time.removeAllItems();
    this.jComboBox_Level.removeAllItems();
    this.jComboBox_DrawType.removeAllItems();

    //Control enable set
    for (Component aItem : this.jToolBar1.getComponents()) {
        aItem.setEnabled(false);
    }
    //this.jButton_OpenData.setEnabled(true);
    this.jSplitButton_OpenData.setEnabled(true);
    this.jPanel_DataSet.setEnabled(false);
    this.jCheckBox_ColorVar.setVisible(false);
    this.jCheckBox_Big_Endian.setVisible(false);
}
 
Example 7
private void checkBoxList_PluginMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_checkBoxList_PluginMouseClicked
    // TODO add your handling code here:
    DefaultListModel listModel = (DefaultListModel) this.checkBoxList_Plugin.getModel();
    int idx = this.checkBoxList_Plugin.getSelectedIndex();
    CheckBoxListEntry item = (CheckBoxListEntry) listModel.getElementAt(idx);
    Application plugin = (Application) item.getValue();
    if (item.isSelected()) {
        parent.loadApplication(plugin);
        parent.validate();
    } else {
        parent.unloadApplication(plugin);
        parent.validate();
    }

    String detailStr = "Name: " + plugin.getName()
            + System.getProperty("line.separator") + "Author: " + plugin.getAuthor()
            + System.getProperty("line.separator") + "Version: " + plugin.getVersion()
            + System.getProperty("line.separator") + "Description: " + plugin.getDescription()
            + System.getProperty("line.separator") + "Jar Path: " + plugin.getJarPath()
            + System.getProperty("line.separator") + "Class Name: " + plugin.getClassName();
    this.jTextArea_PluginDetails.setText(detailStr);
}
 
Example 8
Source Project: PolyGlot   Source File: ScrWordClasses.java    License: MIT License 6 votes vote down vote up
private void deleteWordProperty() {
    WordClass prop = lstProperties.getSelectedValue();
    int position = lstProperties.getSelectedIndex();

    if (prop == null || InfoBox.yesNoCancel("Are you sure?", "This will delete the class from all words."
            + " Values will be irretrievably lost.", core.getRootWindow()) != JOptionPane.YES_OPTION) {
        return;
    }

    try {
        core.getWordClassCollection().deleteNodeById(prop.getId());
    } catch (Exception e) {
        IOHandler.writeErrorLog(e);
        InfoBox.error("Unable to Delete", "Unable to delete property: " + e.getLocalizedMessage(), core.getRootWindow());
    }
    DefaultListModel listModel = (DefaultListModel) lstProperties.getModel();
    listModel.removeElement(prop);

    if (position == 0) {
        lstProperties.setSelectedIndex(position);
    } else {
        lstProperties.setSelectedIndex(position - 1);
    }
}
 
Example 9
Source Project: netbeans   Source File: ClassPathUiSupport.java    License: Apache License 2.0 6 votes vote down vote up
/** Moves items up in the list. The indices array will contain 
 * indices to be selected after the change was done.
 */
public static int[] moveUp( DefaultListModel listModel, int indices[]) {
            
    if( indices == null || indices.length == 0 ) {
        assert false : "MoveUp button should be disabled"; // NOI18N
    }
    
    // Move the items up
    for( int i = 0; i < indices.length; i++ ) {
        Object item = listModel.get( indices[i] );
        listModel.remove( indices[i] );
        listModel.add( indices[i] - 1, item ); 
        // Keep the selection a before
        indices[i] -= 1;
    }
    
    return indices;
    
}
 
Example 10
public void actionPerformed(ActionEvent ev) {
  if (ev != null && ev.getSource() != null) {
    DefaultListModel<Object> src = null, dest = null;
    JList list = null;
    if (ev.getSource() == addBtn) {
      src = availModel;
      dest = filesModel;
      list = availFiles;
    } else if (ev.getSource() == removeBtn) {
      dest = availModel;
      src = filesModel;
      list = includedFiles;
    }
    if (dest != null && src != null & list != null) {
      Object[] values = list.getSelectedValuesList().toArray();
      if (values != null) {
        for (int i = 0; i < values.length; i++) {
          src.removeElement(values[i]);
          dest.addElement(values[i]);
        }
      }
      checkButtons();
    }
  }
}
 
Example 11
Source Project: netbeans   Source File: CustomizerCompile.java    License: Apache License 2.0 6 votes vote down vote up
private void addProcessorButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addProcessorButtonActionPerformed
        final AddAnnotationProcessor panel = new AddAnnotationProcessor();
        final DialogDescriptor desc = new DialogDescriptor(panel, NbBundle.getMessage(CustomizerCompile.class, "LBL_AddAnnotationProcessor_Title")); //NOI18N
        desc.setValid(false);
        panel.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                String fqn = panel.getProcessorFQN();
                desc.setValid(fqn.length() > 0);
            }
        });
        Dialog dlg = DialogDisplayer.getDefault().createDialog(desc);
        dlg.setVisible(true);
        if (desc.getValue() == DialogDescriptor.OK_OPTION) {
            ((DefaultListModel)annotationProcessorsList.getModel()).addElement(panel.getProcessorFQN());
        }
        dlg.dispose();
}
 
Example 12
Source Project: opensim-gui   Source File: MultiFileSelectorPanel.java    License: Apache License 2.0 6 votes vote down vote up
/** Creates new form MultiFileSelectorPanel */
public MultiFileSelectorPanel(Vector<String> initialFileNames, FileFilter fileFilter) {
   this.listModel = new DefaultListModel();
   this.fileNames = initialFileNames;

   initComponents();

   fileName.setFileFilter(fileFilter);

   fileList.setModel(listModel);
    for (String fileName1 : fileNames) {
        listModel.addElement(fileName1);
    }

   fileList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
      public void valueChanged(ListSelectionEvent event) {
         if(event.getValueIsAdjusting()) return;
         listSelectionChanged();
      }
   });

   updatePanel();
}
 
Example 13
Source Project: netbeans   Source File: ManageGroupsPanel.java    License: Apache License 2.0 5 votes vote down vote up
private void removeGroups(Iterable<Group> groups) {
    DefaultListModel model = (DefaultListModel) groupList.getModel();
    for (final Group groupIter : groups) {
        if(groupIter != null) {
            model.removeElement(groupIter.getName());
            RP.post(new Runnable() {
                @Override
                public void run() {
                    groupIter.destroy();
                }
            });
        }
    }
}
 
Example 14
Source Project: ramus   Source File: JSModulesEditor.java    License: GNU General Public License v3.0 5 votes vote down vote up
public void loadModules() {
    String[] streamNames = engine.getStreamNames();
    DefaultListModel model = (DefaultListModel) jList.getModel();
    model.clear();

    Arrays.sort(streamNames);

    for (String streamName : streamNames)
        if (streamName.startsWith(PREFIX))
            model.addElement(new Script(streamName));

}
 
Example 15
Source Project: netbeans   Source File: ManageGroupsPanel.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void propertyChange(PropertyChangeEvent event) {
    if(event.getPropertyName().equals("groupRename")) {
        String oldGroupName = (String)event.getOldValue();
        String newGroupName = (String)event.getNewValue();
        DefaultListModel model = (DefaultListModel) groupList.getModel();
        for(int i = 0; i < model.getSize(); i++) {
            if(((String)model.getElementAt(i)).equals(oldGroupName)) {
                model.setElementAt(newGroupName, i);
            }
        }
    }
}
 
Example 16
Source Project: netbeans   Source File: CategoryPanelFormatters.java    License: Apache License 2.0 5 votes vote down vote up
private void formattersMoveUpButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_formattersMoveUpButtonActionPerformed
    int index = formattersList.getSelectedIndex();
    if (index <= 0) return ;
    Object obj = ((DefaultListModel) formattersList.getModel()).remove(index);
    ((DefaultListModel) formattersList.getModel()).insertElementAt(obj, index - 1);
    formattersList.setSelectedIndex(index - 1);
}
 
Example 17
Source Project: netbeans   Source File: CustomizerLibraries.java    License: Apache License 2.0 5 votes vote down vote up
private void switchLibrary() {
    String loc = librariesLocation.getText();
    LibraryManager man;
    if (loc.trim().length() > -1) {
        try {
            File base = FileUtil.toFile(uiProperties.getProject().getProjectDirectory());
            File location = FileUtil.normalizeFile(PropertyUtils.resolveFile(base, loc));
            URL url = location.toURI().toURL();
            man = LibraryManager.forLocation(url);
        } catch (MalformedURLException ex) {
            Exceptions.printStackTrace(ex);
            //TODO show as error in UI
            man = LibraryManager.getDefault();
        }
    } else {
        man = LibraryManager.getDefault();
    }
    
    
    DefaultListModel[] models = new DefaultListModel[]{
        uiProperties.JAVAC_CLASSPATH_MODEL.getDefaultListModel(),
        uiProperties.JAVAC_PROCESSORPATH_MODEL,
        uiProperties.JAVAC_TEST_CLASSPATH_MODEL,
        uiProperties.ENDORSED_CLASSPATH_MODEL,
        uiProperties.RUN_TEST_CLASSPATH_MODEL
       };
    for (int i = 0; i < models.length; i++) {
        for (Iterator it = ClassPathUiSupport.getIterator(models[i]); it.hasNext();) {
            ClassPathSupport.Item itm = (ClassPathSupport.Item) it.next();
            if (itm.getType() == ClassPathSupport.Item.TYPE_LIBRARY) {
                itm.reassignLibraryManager(man);
            }
        }
    }
    jTabbedPane1.repaint();
    testBroken();
    
}
 
Example 18
Source Project: JByteMod-Beta   Source File: ErrorList.java    License: GNU General Public License v2.0 5 votes vote down vote up
public ErrorList(JByteMod jbm, MyCodeList cl) {
  super(new DefaultListModel<Mistake>());
  this.jbm = jbm;
  this.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 13));
  this.warning = new ImageIcon(Toolkit.getDefaultToolkit().getImage(this.getClass().getResource("/resources/warning.png")));
  this.cl = cl;
  cl.setErrorList(this);
  this.setSelectionModel(new DefaultListSelectionModel() {
    @Override
    public void setSelectionInterval(int index0, int index1) {
      super.setSelectionInterval(-1, -1);
    }
  });
  this.oldRenderer = this.getCellRenderer();
  this.setCellRenderer(new CustomCellRenderer());
  this.addMouseListener(new MouseAdapter() {

    @Override
    public void mouseClicked(MouseEvent e) {
      int index = locationToIndex(e.getPoint());
      Mistake error = getModel().getElementAt(index);
      if (!(error instanceof EmptyMistake)) {
        WebPopOver popOver = new WebPopOver(JByteMod.instance);
        popOver.setMargin(10);
        popOver.setMovable(false);
        popOver.setCloseOnFocusLoss(true);
        popOver.setLayout(new VerticalFlowLayout());
        popOver.add(new JLabel(error.getDesc()));
        popOver.show(jbm, (int) jbm.getMousePosition().getX(), (int) jbm.getMousePosition().getY());
      }
    }
  });
  this.updateErrors();
  SwingUtils.disableSelection(this);
}
 
Example 19
Source Project: netbeans   Source File: CustomizerLibraries.java    License: Apache License 2.0 5 votes vote down vote up
private void updateJars(DefaultListModel model) {
    for (int i = 0; i < model.size(); i++) {
        ClassPathSupport.Item item = (ClassPathSupport.Item) model.get(i);
        if (item.getType() == ClassPathSupport.Item.TYPE_JAR) {
            if (item.getReference() != null) {
                item.updateJarReference(uiProperties.getProject().getAntProjectHelper());
            }
        }
    }
    
}
 
Example 20
private void removeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeActionPerformed
        int[] i = arrayList.getSelectedIndices();
        if(i != null && i.length > 0) {
            if(i.length == 1) {
                ((DefaultListModel)arrayList.getModel()).remove(i[0]);
            } else {
                while(i != null && i.length > 0) {
                    ((DefaultListModel)arrayList.getModel()).remove(i[0]);
                    i = arrayList.getSelectedIndices();
                }
            }
        }
}
 
Example 21
public void actionPerformed(ActionEvent e) {
	if (_classpathList.isSelectionEmpty()
			|| !MainFrame.getInstance().confirm(
					Messages.getString("confirmClassPathRemoval"))) {
		return;
	}
	DefaultListModel model = (DefaultListModel) _classpathList.getModel();
	while (!_classpathList.isSelectionEmpty()) {
		model.remove(_classpathList.getSelectedIndex());
	}
}
 
Example 22
Source Project: dsworkbench   Source File: VillageTagFrame.java    License: Apache License 2.0 5 votes vote down vote up
private void fireAddTagEvent(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_fireAddTagEvent
    Tag tag = null;
    try {
        tag = (Tag) jTagsChooser.getSelectedItem();
    } catch (ClassCastException cce) {
        //no tags availabler
        JOptionPaneHelper.showWarningBox(this, "Keine Gruppen vorhanden. Bitte importiere zuerst Gruppen aus dem Spiel oder lege sie in der Gruppen-Ansicht manuell an.", "Warnung");
        return;
    }
    DefaultListModel model = (DefaultListModel) jTagsList.getModel();
    if (jPlayerName.getText().equals("Mehrfachauswahl")) {
        if (tag == null) {
            return;
        }

        for (int i = 0; i < jVillageList.getItemCount(); i++) {
            Village v = (Village) jVillageList.getItemAt(i);
            if (v.getTribe() != Barbarians.getSingleton()) {
                TagManager.getSingleton().addTag(v, tag.getName());
            }
        }
        if (!model.contains(tag)) {
            model.addElement(tag);
        }
    } else {
        Village selection = (Village) jVillageList.getSelectedItem();
        if ((selection == null) || (tag == null)) {
            return;
        }
        if (!model.contains(tag)) {
            model.addElement(tag);
            TagManager.getSingleton().addTag(selection, tag.getName());
        }
    }
}
 
Example 23
Source Project: tda   Source File: PrefManager.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Populates the cached categories using a new list of categories.
 * 
 * @param categories
 *            populated object of {@link CustomCategory} objects
 */
private void setCategoryCache(DefaultListModel categories) {
    // remove existing categories
    this.cachedCategories.clear();
    for (int f = 0; f < categories.size(); f++) {
        this.cachedCategories.add(categories.get(f));
    }
}
 
Example 24
Source Project: blog   Source File: Main.java    License: Apache License 2.0 5 votes vote down vote up
private static DefaultListModel<String> createListModel() {
	DefaultListModel<String> listModel = new DefaultListModel<String>();

	listModel.addElement("Element 1");
	listModel.addElement("Element 2");
	listModel.addElement("Element 3");
	listModel.addElement("Element 4");

	return listModel;
}
 
Example 25
Source Project: openAGV   Source File: StringSetPropertyEditorPanel.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void setProperty(Property property) {
  fProperty = (StringSetProperty) property;
  DefaultListModel<String> model = new DefaultListModel<>();

  for (String item : fProperty.getItems()) {
    model.addElement(item);
  }

  itemsList.setModel(model);
}
 
Example 26
Source Project: nextreports-designer   Source File: CheckListBox.java    License: Apache License 2.0 5 votes vote down vote up
public CheckListBox() {
    super(new DefaultListModel());
    this.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    this.setDoubleBuffered(true);
    this.setCellRenderer(new CheckListBoxCellRenderer());
    this.addMouseListener(new MouseAdapter() {

    	@Override
        public void mouseClicked(MouseEvent event) {
            if (!SwingUtilities.isLeftMouseButton(event)) {
            	return;
            }
            
            int index = locationToIndex(event.getPoint());
            if (index == -1) {
            	return;
            }

            CheckListItem item = (CheckListItem) getModel().getElementAt(index);
            if (item == null) {
            	return;
            }

            final int checkBoxWidth = UIManager.getIcon("CheckBox.icon").getIconWidth() + 2;

            if (event.getPoint().x < getLocation().x + checkBoxWidth) {
            	onCheck(item);
            }
        }
        
    });
}
 
Example 27
Source Project: openAGV   Source File: StringSetPropertyEditorPanel.java    License: Apache License 2.0 5 votes vote down vote up
private void removeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeButtonActionPerformed
  String value = itemsList.getSelectedValue();

  if (value == null) {
    return;
  }

  DefaultListModel<String> model = (DefaultListModel<String>) itemsList.getModel();
  model.removeElement(value);
}
 
Example 28
private void removeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeButtonActionPerformed
  String value = itemsList.getSelectedValue();

  if (value == null) {
    return;
  }

  DefaultListModel<String> model = (DefaultListModel<String>) itemsList.getModel();
  model.removeElement(value);
}
 
Example 29
Source Project: sc2gears   Source File: ReplaySearch.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Loads the specified replay source file.
 * @param replaySource replay source file to be loaded
 */
private void loadReplaySourceFile( final File replaySource ) {
	try ( final BufferedReader input = new BufferedReader( new InputStreamReader( new FileInputStream( replaySource ), Consts.UTF8 ) ) ) {
		final DefaultListModel< File > model = (DefaultListModel< File >) sourceList.getModel();
		model.removeAllElements();
		
		while ( input.ready() )
			model.addElement( new File( input.readLine() ) );
	} catch ( final Exception e ) {
		e.printStackTrace();
		GuiUtils.showErrorDialog( Language.getText( "module.repSearch.tab.source.failedToLoadRepSource" ) );
	}
}
 
Example 30
public void actionPerformed(ActionEvent e) {
	String cp = getText();
	if (Validator.isEmpty(cp)) {
		signalViolation(Messages.getString("specifyClassPath"));
		return;
	}
	DefaultListModel model = (DefaultListModel) _classpathList.getModel();
	if (_classpathList.isSelectionEmpty()) {
		model.addElement(cp);
		clear();
	} else {
		model.setElementAt(cp, _classpathList.getSelectedIndex());
	}
}