Java Code Examples for javax.swing.DefaultListModel#getSize()
The following examples show how to use
javax.swing.DefaultListModel#getSize() .
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: ListSelectionPanel.java From nextreports-designer with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") private void sort(DefaultListModel model) { // we need a List for sorting int size = model.getSize(); ArrayList list = new ArrayList(); for (int x = 0; x < size; ++x) { Object o = model.get(x); list.add(o); } if (comp != null) { Collections.sort(list, comp); } else { Collections.sort(list); } // update the model with a sorted List for (int x = 0; x < size; ++x) { Object obj = list.get(x); if ((model.getElementAt(x) != null) && !model.getElementAt(x).equals(obj)) { model.set(x, obj); } } }
Example 2
Source File: CSVColumnPanel.java From javamoney-examples with Apache License 2.0 | 6 votes |
private void storeCSVColumnOrder() { DefaultListModel model = (DefaultListModel)getList().getModel(); int[] order = new int[CSVColumnKeys.values().length]; for(int len = 0; len < model.getSize(); ++len) { CSVColumnKeys key = (CSVColumnKeys)model.get(len); order[len] = key.ordinal(); } setCSVColumnOrder(order); }
Example 3
Source File: SelectRootsPanel.java From netbeans with Apache License 2.0 | 6 votes |
private void browse(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browse try { final Collection<Integer> added = new ArrayList<>(); final List<? extends String> paths = browseCall.call(); if (paths != null) { final DefaultListModel<URI> lm = (DefaultListModel<URI>) sources.getModel(); final Set<URI> contained = new HashSet<>(Collections.list(lm.elements())); int index = sources.getSelectedIndex(); index = index < 0 ? lm.getSize() : index + 1; for (String path : paths) { for (URI uri : convertor.call(path)) { if (!contained.contains(uri)) { lm.add(index, uri); added.add(index); index++; } } } } select(added); } catch (Exception ex) { Exceptions.printStackTrace(ex); } }
Example 4
Source File: ConfigurableUserAccessDialog.java From rapidminer-studio with GNU Affero General Public License v3.0 | 6 votes |
/** * Adds the element sorted to the model * * @param model * @param element * @return index of the new element */ private int addElement(DefaultListModel<String> model, String element) { if (model.isEmpty()) { model.addElement(element); return 0; } else { for (int j = 0; j < model.getSize(); j++) { int compareValue = String.CASE_INSENSITIVE_ORDER.compare(model.getElementAt(j).toString(), element); if (compareValue > 0) { model.add(j, element); return j; } if (j == model.getSize() - 1) { model.add(j + 1, element); return j + 1; } } } // sth went wrong return -1; }
Example 5
Source File: ClassPathFormImpl.java From beast-mcmc with GNU Lesser General Public License v2.1 | 5 votes |
public void actionPerformed(ActionEvent e) { DefaultListModel model = (DefaultListModel) _classpathList.getModel(); int x = _classpathList.getSelectedIndex(); if (x == -1 || x >= model.getSize() - 1) { return; } Object o = model.get(x + 1); model.set(x + 1, model.get(x)); model.set(x, o); _classpathList.setSelectedIndex(x + 1); }
Example 6
Source File: BreakpointNestedGroupsDialog.java From netbeans with Apache License 2.0 | 5 votes |
private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addButtonActionPerformed int[] indexes = availableGroupsList.getSelectedIndices(); DefaultListModel availableModel = (DefaultListModel) availableGroupsList.getModel(); DefaultListModel displayedModel = (DefaultListModel) displayedGroupsList.getModel(); int at = displayedModel.getSize(); for (int i = indexes.length - 1; i >= 0; i--) { Object element = availableModel.remove(indexes[i]); displayedModel.add(at, element); } }
Example 7
Source File: ManageGroupsPanel.java From netbeans with Apache License 2.0 | 5 votes |
@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 8
Source File: TroopFilterDialog.java From dsworkbench with Apache License 2.0 | 5 votes |
private void fireSaveFilterSettingsEvent(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_fireSaveFilterSettingsEvent String setName = jNewFilterName.getText(); DefaultListModel filterModel = (DefaultListModel) jFilterList.getModel(); if (setName == null || setName.length() == 0) { JOptionPaneHelper.showInformationBox(this, "Bitte einen Namen für das neue Filterset angeben", "Information"); return; } if (filterModel.getSize() == 0) { JOptionPaneHelper.showInformationBox(this, "Ein Filterset muss mindestens einen Eintrag enthalten", "Information"); return; } if (filterSets.get(setName) != null) { if (JOptionPaneHelper.showQuestionConfirmBox(this, "Das Filterset '" + setName + "' existiert bereits.\nMöchtest du es überschreiben?", "Bestätigung", "Nein", "Ja") != JOptionPane.OK_OPTION) { return; } } StringBuilder b = new StringBuilder(); b.append(setName).append(","); List<TroopFilterElement> elements = new LinkedList<>(); for (int j = 0; j < filterModel.size(); j++) { TroopFilterElement elem = (TroopFilterElement) filterModel.get(j); elements.add(new TroopFilterElement(elem.getUnit(), elem.getMin(), elem.getMax())); } filterSets.put(setName, elements); updateFilterSetList(); saveFilterSets(); }
Example 9
Source File: JListBinding.java From PyramidShader with GNU General Public License v3.0 | 5 votes |
public void get(IValidatable bean) { try { DefaultListModel model = (DefaultListModel) _list.getModel(); final int size = model.getSize(); List<Object> list = new ArrayList<Object>(size); for (int i = 0; i < size; i++) { list.add(model.get(i)); } PropertyUtils.setProperty(bean, _property, list); } catch (Exception e) { throw new BindingException(e); } }
Example 10
Source File: BuildQueuePanel.java From freecol with GNU General Public License v2.0 | 5 votes |
/** * Update all the lists and buttons, using * {@link #updateBuildingList()} and * {@link #updateUnitList()} */ private final void updateAllLists() { final DefaultListModel<BuildableType> current = (DefaultListModel<BuildableType>)this.buildQueueList.getModel(); this.featureContainer.clear(); for (Enumeration<BuildableType> e = current.elements(); e.hasMoreElements();) { BuildableType type = e.nextElement(); if (getMinimumIndex(type) >= 0) { featureContainer.addFeatures(type); } else { current.removeElement(type); } } // ATTENTION: buildings must be updated first, since units // might depend on the build ability of an unbuildable // building updateBuildingList(); updateUnitList(); // Update the buy button final boolean pay = getSpecification() .getBoolean(GameOptions.PAY_FOR_BUILDING); BuildableType bt = (current.getSize() <= 0) ? null : current.getElementAt(0); this.buyBuildable.setEnabled(bt != null && pay && this.colony.canPayToFinishBuilding(bt)); this.setBuyLabel(bt); // Update the construction panel if (current.getSize() > 0) { this.constructionPanel.update(current.getElementAt(0)); } else if (current.getSize() == 0) { this.constructionPanel.update(); // generates Building: Nothing } }
Example 11
Source File: ParamEstimatorPanel.java From iBioSim with Apache License 2.0 | 5 votes |
public List<String> getSelectedParameters() { DefaultListModel lm2 = (DefaultListModel) list2.getModel(); List<String> parameters = new ArrayList<String>(); for (int i = 0; i < lm2.getSize(); i++) { parameters.add((String) lm2.get(i)); } return parameters; }
Example 12
Source File: CustomizerTesting.java From netbeans with Apache License 2.0 | 5 votes |
private List<BasePathSupport.Item> convertToList(DefaultListModel<BasePathSupport.Item> listModel) { List<BasePathSupport.Item> items = new ArrayList<>(listModel.getSize()); for (int i = 0; i < listModel.getSize(); i++) { items.add(listModel.get(i)); } return items; }
Example 13
Source File: GUIRegistrationPanel.java From netbeans with Apache License 2.0 | 5 votes |
private void keyStrokeRemoveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_keyStrokeRemoveActionPerformed DefaultListModel lm = (DefaultListModel)shortcutsList.getModel(); Object[] selected = shortcutsList.getSelectedValues(); if (selected.length > 0) { int idx = shortcutsList.getSelectionModel().getMinSelectionIndex(); for (int i = 0; i < selected.length; i++) { lm.removeElement(selected[i]); } if (lm.getSize() > 0) { idx = (idx > 0) ? idx -1 : 0; shortcutsList.setSelectedIndex(idx); } } checkValidity(); }
Example 14
Source File: FrmGifAnimator.java From MeteoInfo with GNU Lesser General Public License v3.0 | 5 votes |
private void jButton_CreateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_CreateActionPerformed // TODO add your handling code here: this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); String path = System.getProperty("user.dir"); File pathDir = new File(path); JFileChooser saveDlg = new JFileChooser(); saveDlg.setAcceptAllFileFilterUsed(false); saveDlg.setCurrentDirectory(pathDir); String[] fileExts = new String[]{"gif"}; GenericFileFilter gifFileFilter = new GenericFileFilter(fileExts, "Gif File (*.gif)"); saveDlg.setFileFilter(gifFileFilter); if (JFileChooser.APPROVE_OPTION == saveDlg.showSaveDialog(this)) { File outfile = saveDlg.getSelectedFile(); String extent = ((GenericFileFilter) saveDlg.getFileFilter()).getFileExtent(); String fileName = outfile.getAbsolutePath(); if (!fileName.substring(fileName.length() - extent.length()).equals(extent)) { fileName = fileName + "." + extent; } DefaultListModel listModel = (DefaultListModel) this.jList_ImageFiles.getModel(); List<String> fns = new ArrayList<String>(); for (int i = 0; i < listModel.getSize(); i++) { fns.add(listModel.get(i).toString()); } int delay = Integer.parseInt(this.jTextField_Delay.getText()); int repeat = Integer.parseInt(this.jTextField_Repeat.getText()); ImageUtil.createGifAnimator(fns, fileName, delay, repeat); JOptionPane.showMessageDialog(null, "Gif animator file is created!"); } this.setCursor(Cursor.getDefaultCursor()); }
Example 15
Source File: PathsCustomizer.java From netbeans with Apache License 2.0 | 5 votes |
private static DefaultTreeModel toTreeModel(final DefaultListModel lm, final String rootName) { DefaultMutableTreeNode root = new DefaultMutableTreeNode(rootName); for (int i = 0; i < lm.getSize(); i++) { Object obj = lm.getElementAt(i); if (obj instanceof ClassPathSupport.Item) { root.add(toTreeNode(obj)); } } return new DefaultTreeModel(root); }
Example 16
Source File: CSVColumnPanel.java From javamoney-examples with Apache License 2.0 | 5 votes |
private void moveColumn(String action) { DefaultListModel model = (DefaultListModel)getList().getModel(); Object object = getList().getSelectedValue(); int index = getList().getSelectedIndex(); if(action.equals(ACTION_DOWN) == true) { ++index; if(index < model.getSize()) { model.remove(index - 1); model.add(index, object); getList().setSelectedIndex(index); storeCSVColumnOrder(); } } else { --index; if(index > -1) { model.remove(index + 1); model.add(index, object); getList().setSelectedIndex(index); storeCSVColumnOrder(); } } }
Example 17
Source File: Browser.java From joshua with Apache License 2.0 | 5 votes |
private static void search(int fromIndex) { final String query = searchBox.getText(); DefaultListModel oneBestListModel = (DefaultListModel) oneBestList.getModel(); for (int i = fromIndex; i < oneBestListModel.getSize(); i++) { String reference = (String) oneBestListModel.getElementAt(i); if (reference.contains(query)) { // found the query oneBestList.setSelectedIndex(i); oneBestList.ensureIndexIsVisible(i); searchBox.setBackground(Color.white); return; } } searchBox.setBackground(Color.red); }
Example 18
Source File: JListBinding.java From jmkvpropedit with BSD 2-Clause "Simplified" License | 5 votes |
public void get(IValidatable bean) { try { DefaultListModel model = (DefaultListModel) _list.getModel(); final int size = model.getSize(); List<Object> list = new ArrayList<Object>(size); for (int i = 0; i < size; i++) { list.add(model.get(i)); } PropertyUtils.setProperty(bean, _property, list); } catch (Exception e) { throw new BindingException(e); } }
Example 19
Source File: ListTransferHandler.java From marathonv5 with Apache License 2.0 | 5 votes |
protected void importString(JComponent c, String str) { JList target = (JList) c; DefaultListModel listModel = (DefaultListModel) target.getModel(); int index = target.getSelectedIndex(); // Prevent the user from dropping data back on itself. // For example, if the user is moving items #4,#5,#6 and #7 and // attempts to insert the items after item #5, this would // be problematic when removing the original items. // So this is not allowed. if (indices != null && index >= indices[0] - 1 && index <= indices[indices.length - 1]) { indices = null; return; } int max = listModel.getSize(); if (index < 0) { index = max; } else { index++; if (index > max) { index = max; } } addIndex = index; String[] values = str.split("\n"); addCount = values.length; for (String value : values) { listModel.add(index++, value); } }
Example 20
Source File: FrmJoinNCFiles.java From MeteoInfo with GNU Lesser General Public License v3.0 | 5 votes |
private void jButton_SelectAllActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_SelectAllActionPerformed // TODO add your handling code here: DefaultListModel listModel_all = (DefaultListModel)this.jList_AllFiles.getModel(); DefaultListModel listModel_sel = (DefaultListModel)this.jList_SelectedFiles.getModel(); listModel_sel.clear(); for (int i = 0; i < listModel_all.getSize(); i++){ listModel_sel.addElement(listModel_all.getElementAt(i)); } }