List of usage examples for javax.swing DefaultListModel set
public E set(int index, E element)
From source file:Main.java
@Override public boolean importData(TransferHandler.TransferSupport support) { if (!this.canImport(support)) { return false; }//from w ww .j a v a 2 s.co m Transferable t = support.getTransferable(); String data = null; try { data = (String) t.getTransferData(DataFlavor.stringFlavor); if (data == null) { return false; } } catch (Exception e) { e.printStackTrace(); return false; } JList.DropLocation dropLocation = (JList.DropLocation) support.getDropLocation(); int dropIndex = dropLocation.getIndex(); JList<String> targetList = (JList<String>) support.getComponent(); DefaultListModel<String> listModel = (DefaultListModel<String>) targetList.getModel(); if (dropLocation.isInsert()) { listModel.add(dropIndex, data); } else { listModel.set(dropIndex, data); } return true; }
From source file:dnd.ListTransferHandler.java
public boolean importData(TransferHandler.TransferSupport info) { if (!info.isDrop()) { return false; }/* www . ja v a 2 s . co m*/ JList list = (JList) info.getComponent(); DefaultListModel listModel = (DefaultListModel) list.getModel(); JList.DropLocation dl = (JList.DropLocation) info.getDropLocation(); int index = dl.getIndex(); boolean insert = dl.isInsert(); // Get the string that is being dropped. Transferable t = info.getTransferable(); String data; try { data = (String) t.getTransferData(DataFlavor.stringFlavor); } catch (Exception e) { return false; } // Perform the actual import. if (insert) { listModel.add(index, data); } else { listModel.set(index, data); } return true; }
From source file:DropDemo.java
public boolean importData(TransferHandler.TransferSupport info) { if (!info.isDrop()) { return false; }/*from ww w . j ava 2s . co m*/ JList list = (JList) info.getComponent(); DefaultListModel listModel = (DefaultListModel) list.getModel(); JList.DropLocation dl = (JList.DropLocation) info.getDropLocation(); int index = dl.getIndex(); boolean insert = dl.isInsert(); // Get the string that is being dropped. Transferable t = info.getTransferable(); String data; try { data = (String) t.getTransferData(DataFlavor.stringFlavor); } catch (Exception e) { return false; } // Perform the actual import. if (insert) { listModel.add(index, data); } else { listModel.set(index, data); } return true; }
From source file:ListCutPaste.java
/** * Perform the actual data import.// w w w. j ava2 s . c om */ public boolean importData(TransferHandler.TransferSupport info) { String data = null; // If we can't handle the import, bail now. if (!canImport(info)) { return false; } JList list = (JList) info.getComponent(); DefaultListModel model = (DefaultListModel) list.getModel(); // Fetch the data -- bail if this fails try { data = (String) info.getTransferable().getTransferData(DataFlavor.stringFlavor); } catch (UnsupportedFlavorException ufe) { System.out.println("importData: unsupported data flavor"); return false; } catch (IOException ioe) { System.out.println("importData: I/O exception"); return false; } if (info.isDrop()) { // This is a drop JList.DropLocation dl = (JList.DropLocation) info.getDropLocation(); int index = dl.getIndex(); if (dl.isInsert()) { model.add(index, data); return true; } else { model.set(index, data); return true; } } else { // This is a paste int index = list.getSelectedIndex(); // if there is a valid selection, // insert data after the selection if (index >= 0) { model.add(list.getSelectedIndex() + 1, data); // else append to the end of the list } else { model.addElement(data); } return true; } }
From source file:nz.govt.natlib.ndha.manualdeposit.metadata.MetaDataConfiguratorPresenter.java
public void moveLookupItem(boolean up) { if (canMoveLookupItem(up)) { int currentIndex = theDataLookupList.getSelectedIndex(); int otherIndex; if (up) { otherIndex = currentIndex - 1; } else {// w w w. j a v a 2s . com otherIndex = currentIndex + 1; } DefaultListModel model = (DefaultListModel) theDataLookupList.getModel(); MetaDataListValues currentItem = (MetaDataListValues) model.get(currentIndex); currentItem.setSortOrder(otherIndex); MetaDataListValues itemToSwapWith = (MetaDataListValues) model.get(otherIndex); itemToSwapWith.setSortOrder(currentIndex); model.set(currentIndex, itemToSwapWith); model.set(otherIndex, currentItem); theDataLookupList.setSelectedIndex(otherIndex); setDirty(true); updateDataLookupValues(); configuratorFrame.checkButtons(); } }
From source file:nz.govt.natlib.ndha.manualdeposit.metadata.MetaDataConfiguratorPresenter.java
public void saveCMSValueItem(String value) throws MetaDataException { if (theCmsMappingsList.getSelectedIndex() > -1) { DefaultListModel model = (DefaultListModel) theCmsMappingsList.getModel(); model.set(theCmsMappingsList.getSelectedIndex(), value); theCmsMappingsList.setSelectedIndex(-1); } else {/*from w w w .ja v a 2 s . c o m*/ throw new MetaDataException("Invalid selection saving CMS field data"); } }
From source file:nz.govt.natlib.ndha.manualdeposit.metadata.MetaDataConfiguratorPresenter.java
public void updateCmsLookupValue(String newValue) { if (theCmsMappingsList.getSelectedIndex() > -1) { DefaultListModel model = (DefaultListModel) theCmsMappingsList.getModel(); model.set(theCmsMappingsList.getSelectedIndex(), newValue); theCmsMappingsList.setSelectedIndex(-1); updateDataLookupValues();// ww w.j a v a 2 s .c o m } else { configuratorFrame.showError(errorHeader, "Invalid selection saving CMS lookup data"); return; } }
From source file:org.isatools.isacreatorconfigurator.configui.DataEntryPanel.java
private void swapElements(JList list, DefaultListModel model, int a, int b) { Object o1 = model.getElementAt(a); Object o2 = model.getElementAt(b); model.set(a, o2); model.set(b, o1);//ww w .java 2s . co m // Swap elements in list too List<Display> fields = tableFields.get(getCurrentlySelectedTable()); Display e1 = fields.get(a); Display e2 = fields.get(b); fields.set(a, e2); fields.set(b, e1); list.setSelectedIndex(b); list.ensureIndexIsVisible(b); }