List of usage examples for javax.swing DefaultListModel get
public E get(int index)
From source file:Main.java
public static void main(final String args[]) { String labels[] = { "A", "B", "C", "D", "E" }; JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); DefaultListModel model = new DefaultListModel(); model.ensureCapacity(1000);/*from w w w .j a v a 2 s.co m*/ for (int i = 0; i < 100; i++) { for (int j = 0; j < 5; j++) { model.addElement(labels[j]); } } System.out.println(model.get(1)); JList jlist2 = new JList(model); jlist2.setVisibleRowCount(4); jlist2.setFixedCellHeight(12); jlist2.setFixedCellWidth(200); JScrollPane scrollPane2 = new JScrollPane(jlist2); frame.add(scrollPane2, BorderLayout.CENTER); frame.setSize(300, 350); frame.setVisible(true); }
From source file:net.sf.jabref.gui.ContentSelectorDialog2.java
private static int findPos(DefaultListModel<String> lm, String item) { for (int i = 0; i < lm.size(); i++) { String s = lm.get(i); if (item.compareToIgnoreCase(s) < 0) { // item precedes s return i; }//from ww w .j a v a2 s . c om } return lm.size(); }
From source file:edu.ku.brc.af.ui.forms.formatters.UIFormatterListEdtDlg.java
/** * Sets the selected formatter as the default. *//*from w w w . jav a 2 s . c o m*/ protected void setAsDefFormatter() { UIFieldFormatter selected = (UIFieldFormatter) formatList.getSelectedValue(); DefaultListModel model = (DefaultListModel) formatList.getModel(); for (int i = 0; i < model.getSize(); i++) { UIFieldFormatter uif = (UIFieldFormatter) model.get(i); uif.setDefault(uif == selected); } if (fieldInfo != null) { fieldInfo.setFormatter(selected); } setHasChanged(true); formatList.repaint(); }
From source file:de.dakror.virtualhub.client.dialog.ChooseCatalogDialog.java
public static void show(ClientFrame frame, final JSONArray data) { final JDialog dialog = new JDialog(frame, "Katalog whlen", true); dialog.setSize(400, 300);/* w w w .j av a 2s .c om*/ dialog.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); dialog.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { Client.currentClient.disconnect(); System.exit(0); } }); JPanel contentPane = new JPanel(new FlowLayout(FlowLayout.LEADING, 0, 0)); dialog.setContentPane(contentPane); DefaultListModel dlm = new DefaultListModel(); for (int i = 0; i < data.length(); i++) { try { dlm.addElement(data.getJSONObject(i).getString("name")); } catch (JSONException e) { e.printStackTrace(); } } final JList catalogs = new JList(dlm); catalogs.setDragEnabled(false); catalogs.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JScrollPane jsp = new JScrollPane(catalogs, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); jsp.setPreferredSize(new Dimension(396, 200)); contentPane.add(jsp); JPanel mods = new JPanel(new GridLayout(1, 2)); mods.setPreferredSize(new Dimension(50, 22)); mods.add(new JButton(new AbstractAction("+") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { String name = JOptionPane.showInputDialog(dialog, "Bitte geben Sie den Namen des neuen Katalogs ein.", "Katalog hinzufgen", JOptionPane.PLAIN_MESSAGE); if (name != null && name.length() > 0) { DefaultListModel dlm = (DefaultListModel) catalogs.getModel(); for (int i = 0; i < dlm.getSize(); i++) { if (dlm.get(i).toString().equals(name)) { JOptionPane.showMessageDialog(dialog, "Es existert bereits ein Katalog mit diesem Namen!", "Katalog bereits vorhanden!", JOptionPane.ERROR_MESSAGE); actionPerformed(e); return; } } try { dlm.addElement(name); JSONObject o = new JSONObject(); o.put("name", name); o.put("sources", new JSONArray()); o.put("tags", new JSONArray()); data.put(o); Client.currentClient.sendPacket(new Packet0Catalogs(data)); } catch (Exception e1) { e1.printStackTrace(); } } } })); mods.add(new JButton(new AbstractAction("-") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { if (catalogs.getSelectedIndex() != -1) { if (JOptionPane.showConfirmDialog(dialog, "Sind Sie sicher, dass Sie diesen\r\nKatalog unwiderruflich lschen wollen?", "Katalog lschen", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) { DefaultListModel dlm = (DefaultListModel) catalogs.getModel(); data.remove(catalogs.getSelectedIndex()); dlm.remove(catalogs.getSelectedIndex()); try { Client.currentClient.sendPacket(new Packet0Catalogs(data)); } catch (IOException e1) { e1.printStackTrace(); } } } } })); contentPane.add(mods); JLabel l = new JLabel(""); l.setPreferredSize(new Dimension(396, 14)); contentPane.add(l); JSeparator sep = new JSeparator(JSeparator.HORIZONTAL); sep.setPreferredSize(new Dimension(396, 10)); contentPane.add(sep); JPanel buttons = new JPanel(new GridLayout(1, 2)); buttons.setPreferredSize(new Dimension(396, 22)); buttons.add(new JButton(new AbstractAction("Abbrechen") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { Client.currentClient.disconnect(); System.exit(0); } })); buttons.add(new JButton(new AbstractAction("Katalog whlen") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { if (catalogs.getSelectedIndex() != -1) { try { Client.currentClient .setCatalog(new Catalog(data.getJSONObject(catalogs.getSelectedIndex()))); Client.currentClient.frame.setTitle("- " + Client.currentClient.getCatalog().getName()); dialog.dispose(); } catch (JSONException e1) { e1.printStackTrace(); } } } })); dialog.add(buttons); dialog.setLocationRelativeTo(frame); dialog.setResizable(false); dialog.setVisible(true); }
From source file:net.sf.jabref.gui.ContentSelectorDialog2.java
private void applyChanges() { boolean changedFieldSet = false; // Watch if we need to rebuild entry editors // First remove the mappings for fields that have been deleted. // If these were re-added, they will be added below, so it doesn't // cause any harm to remove them here. for (String fieldName : removedFields) { metaData.clearContentSelectors(fieldName); changedFieldSet = true;//from w w w . j av a 2s . c o m } // Cycle through all fields that we have created listmodels for: for (Map.Entry<String, DefaultListModel<String>> entry : wordListModels.entrySet()) { // For each field name, store the values: if ((entry.getKey() == null) || FIELD_FIRST_LINE.equals(entry.getKey())) { continue; } DefaultListModel<String> lm = entry.getValue(); int start = 0; // Avoid storing the <new word> marker if it is there: if (!lm.isEmpty()) { while ((start < lm.size()) && lm.get(start).equals(WORD_FIRSTLINE_TEXT)) { start++; } } if (metaData.getContentSelectors(entry.getKey()).isEmpty()) { changedFieldSet = true; List<String> data = new ArrayList<>(); for (int wrd = start; wrd < lm.size(); wrd++) { String word = lm.get(wrd); data.add(word); } metaData.setContentSelectors(entry.getKey(), data); } } // TODO: remove metadata for removed selector field. panel.markNonUndoableBaseChanged(); // Update all selectors in the current BasePanel. if (changedFieldSet) { panel.rebuildAllEntryEditors(); } else { panel.updateAllContentSelectors(); } panel.getAutoCompleters() .addContentSelectorValuesToAutoCompleters(panel.getBibDatabaseContext().getMetaData()); }
From source file:gtu._work.ui.ObnfInsertCreaterUI.java
private void dbFieldListMousePreformd(MouseEvent evt) { if (JMouseEventUtil.buttonLeftClick(1, evt)) { KeyValue kv = (KeyValue) dbFieldList.getSelectedValue(); if (kv != null) { dbFieldText.setText(kv.key); dbValue.setText(kv.value);// w ww .jav a 2 s .c o m pkCheckBox.setSelected(kv.pk); } } if (JMouseEventUtil.buttonRightClick(1, evt)) { JPopupMenuUtil.newInstance(dbFieldList).addJMenuItem("/?", new ActionListener() { public void actionPerformed(ActionEvent e) { List<KeyValue> list = new ArrayList<KeyValue>(); DefaultListModel model = (DefaultListModel) dbFieldList.getModel(); for (int ii = 0; ii < model.getSize(); ii++) { KeyValue kv = (KeyValue) model.get(ii); list.add(kv); } Collections.sort(list, new Comparator<KeyValue>() { @Override public int compare(KeyValue o1, KeyValue o2) { return o1.key.compareTo(o2.key); } }); DefaultListModel model1 = new DefaultListModel(); for (KeyValue kv : list) { model1.addElement(kv); } dbFieldList.setModel(model1); } }).addJMenuItem("/?PK", new ActionListener() { public void actionPerformed(ActionEvent e) { Object[] values = dbFieldList.getSelectedValues(); if (values != null) { for (Object v : values) { KeyValue kv = (KeyValue) v; kv.pk = !kv.pk; } } } }).applyEvent(evt).show(); } }
From source file:edu.ku.brc.specify.tasks.subpane.VisualQueryPanel.java
/** * @return the RecordSet of chosen items. *///from w w w .j a v a 2s. c om private RecordSetIFace createRecordSet() { RecordSetIFace rs = null; DefaultListModel model = (DefaultListModel) recSetList.getModel(); if (model.getSize() > 0) { rs = RecordSetFactory.getInstance().createRecordSet(); rs.setDbTableId(TABLE_IDS[typeCBX.getSelectedIndex()]); for (int i = 0; i < model.getSize(); i++) { LatLonPoint llp = (LatLonPoint) model.get(i); rs.addItem(llp.getLocId()); } } return rs; }
From source file:edu.ku.brc.specify.tasks.subpane.VisualQueryPanel.java
/** * Moves selected items from one list to the other. * @param srcList// w ww . ja v a2s. c o m * @param srcHash * @param dstList * @param dstHash */ private void moveItems(final JList srcList, final HashSet<Integer> srcHash, final JList dstList, final HashSet<Integer> dstHash) { int inx = srcList.getSelectedIndex(); if (inx > -1) { DefaultListModel srcModel = (DefaultListModel) srcList.getModel(); DefaultListModel dstModel = (DefaultListModel) dstList.getModel(); int[] indexes = srcList.getSelectedIndices(); ArrayList<LatLonPoint> llpList = new ArrayList<LatLonPoint>(indexes.length); for (int selInx : indexes) { LatLonPoint llp = (LatLonPoint) srcModel.get(selInx); llpList.add(llp); if (!dstHash.contains(llp.getLocId())) { dstModel.addElement(llp); dstHash.add(llp.getLocId()); } } for (LatLonPoint llp : llpList) { srcModel.removeElement(llp); srcHash.remove(llp.getLocId()); } } }
From source file:es.emergya.ui.plugins.admin.aux1.SummaryAction.java
private void reorder(int inicio, int fin) { boolean sentido = inicio < fin; LinkedList<Object> aSubir = new LinkedList<Object>(); LinkedList<Object> resultado = new LinkedList<Object>(); for (Object o : right.getSelectedValues()) { aSubir.add(o);//w ww. ja va 2 s . c o m } final DefaultListModel defaultListModel = (DefaultListModel) right.getModel(); if (log.isTraceEnabled()) { log.trace("Elementos seleccionados:"); for (Object o : aSubir) { log.trace(o + " " + o.getClass()); } } for (int i = inicio; (sentido ? i <= fin : fin <= i); i = (sentido ? i + 1 : i - 1)) { Object o = defaultListModel.get(i); if (aSubir.contains(o) && i != inicio) { Object siguiente = resultado.pollLast(); log.trace("Cambiamos " + o + " por " + siguiente); resultado.add(o); resultado.add(siguiente); } else { log.trace("Aadimos " + o); resultado.add(o); } } ((DefaultListModel) right.getModel()).removeAllElements(); log.trace("Nueva lista: "); int inicio2 = (sentido ? 0 : resultado.size() - 1); int fin2 = (sentido ? resultado.size() - 1 : 0); for (int i = inicio2; (sentido ? i <= fin2 : fin2 <= i); i = (sentido ? i + 1 : i - 1)) { Object o = resultado.get(i); log.trace("Nueva lista >" + o); ((DefaultListModel) right.getModel()).addElement(o); } int seleccion[] = new int[aSubir.size()]; int k = 0; for (Integer i = 0; i < right.getModel().getSize(); i++) { if (aSubir.contains(right.getModel().getElementAt(i))) { seleccion[k++] = i; } } right.setSelectedIndices(seleccion); right.updateUI(); }
From source file:de.tor.tribes.ui.views.DSWorkbenchReTimerFrame.java
private void fireApplyTroopFiltersEvent(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_fireApplyTroopFiltersEvent if (evt.getSource() == jApplyFiltersButton) { DefaultListModel filterModel = (DefaultListModel) jFilterList.getModel(); List<Integer> rowsToRemove = new LinkedList<Integer>(); int removeCount = 0; for (int i = 0; i < jResultTable.getRowCount(); i++) { //go through all rows in attack table and get source village Village v = (Village) jResultTable.getValueAt(i, 0); for (int j = 0; j < filterModel.size(); j++) { //check for all filters if villag is allowed if (!((TroopFilterElement) filterModel.get(j)).allowsVillage(v)) { //village is not allowed, add to remove list int row = jResultTable.convertRowIndexToModel(i); rowsToRemove.add(row); removeCount++;/*from ww w . jav a 2s .c o m*/ } } } jResultTable.getSelectionModel().setValueIsAdjusting(true); for (int row : rowsToRemove) { jResultTable.getSelectionModel().addSelectionInterval(row, row); } jResultTable.getSelectionModel().setValueIsAdjusting(false); } jFilterDialog.setVisible(false); }