List of usage examples for javax.swing DefaultListModel add
public void add(int index, E element)
From source file:DropDemo.java
public boolean importData(TransferHandler.TransferSupport info) { if (!info.isDrop()) { return false; }//from w w w.j ava 2 s.c o 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:br.upe.ecomp.dosa.view.wizard.WizardAction.java
private void pickListUpAction(final JList list) { final DefaultListModel selectedListModel = (DefaultListModel) list.getModel(); final int selectedIndex = list.getSelectedIndex(); Object element;//from ww w. j av a 2 s. c om if (selectedIndex > 0) { element = list.getSelectedValue(); selectedListModel.remove(selectedIndex); selectedListModel.add(selectedIndex - 1, element); } }
From source file:br.upe.ecomp.dosa.view.wizard.WizardAction.java
private void pickListDownAction(final JList list) { final DefaultListModel selectedListModel = (DefaultListModel) list.getModel(); final int selectedIndex = list.getSelectedIndex(); final int listSize = selectedListModel.getSize(); Object element;/*from w ww. ja v a 2s . c o m*/ if (selectedIndex < listSize - 1) { element = list.getSelectedValue(); selectedListModel.remove(selectedIndex); selectedListModel.add(selectedIndex + 1, element); } }
From source file:ListCutPaste.java
/** * Perform the actual data import.// www .jav a2s . c o m */ 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:io.neocdtv.simpleplayer.ui.PlaylistTransferHandler.java
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;//from ww w . j a va 2s . c o m 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); } }
From source file:DropDemo.java
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;/*ww w .j a v a2s.c o m*/ 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 (int i = 0; i < values.length; i++) { listModel.add(index++, values[i]); } }
From source file:ExtendedDnDDemo.java
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;/*from ww w .j a v a 2 s . co m*/ 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 (int i = 0; i < values.length; i++) { listModel.add(index++, values[i]); } }
From source file:nz.govt.natlib.ndha.manualdeposit.dialogs.ApplicationProperties.java
private void setupForm(final String settingsPath) { this.setTitle("System Properties"); try {/*from w ww . ja va 2 s. c om*/ theFormControl = new FormControl(this, settingsPath); } catch (Exception ex) { LOG.error("Error loading form parameters", ex); } // Set fonts isSystemChange = true; final GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); final Font[] fonts = env.getAllFonts(); DefaultListModel model = new DefaultListModel(); for (int i = 0; i < fonts.length; i++) { final Font font = fonts[i]; model.add(i, font.getName()); } lstFont.setModel(model); // Set styles model = new DefaultListModel(); model.addElement("Plain"); model.addElement("Bold"); model.addElement("Italic"); model.addElement("Bold Italic"); lstStyle.setModel(model); // Set sizes model = new DefaultListModel(); model.addElement("8"); model.addElement("10"); model.addElement("12"); model.addElement("14"); model.addElement("18"); model.addElement("20"); model.addElement("22"); model.addElement("24"); lstSize.setModel(model); txtFontSize.getDocument().addDocumentListener(new DocumentListener() { public void changedUpdate(final DocumentEvent e) { updateFontSize(); } public void removeUpdate(final DocumentEvent e) { updateFontSize(); } public void insertUpdate(final DocumentEvent e) { updateFontSize(); } }); model = new DefaultListModel(); for (String favourite : personalSettings.getFavourites()) { model.addElement(favourite); } lstFavourites.setModel(model); model = new DefaultListModel(); for (PersonalSettings.FileDescriptions descriptions : personalSettings.getFilesToIgnore()) { model.addElement(descriptions); } lstFilesToIgnore.setModel(model); final DefaultComboBoxModel cmbModel = new DefaultComboBoxModel(); for (PersonalSettings.TextPosition position : PersonalSettings.TextPosition.values()) { cmbModel.addElement(position); } cmbTextPosition.setModel(cmbModel); chkSortRunning.setSelected(personalSettings.isSortRunningAscending()); chkSortPending.setSelected(personalSettings.isSortPendingAscending()); chkSortFailed.setSelected(personalSettings.isSortFailedAscending()); chkSortDeposited.setSelected(personalSettings.isSortDepositedAscending()); chkSortComplete.setSelected(personalSettings.isSortCompleteAscending()); txtNoOfRetries.setText(String.format("%d", personalSettings.getNoOfRetries())); isSystemChange = false; }
From source file:org.nuclos.client.wizard.steps.NuclosEntitySQLLayoutStep.java
private void buttonDownAttributeAction() { int iSelected = listAttributeOrder.getSelectedIndex(); if (iSelected < 0 || iSelected >= listAttributeOrder.getModel().getSize() - 1) return;/*from w w w . ja va2s .co m*/ DefaultListModel model = (DefaultListModel) listAttributeOrder.getModel(); Object obj = model.remove(iSelected); model.add(iSelected + 1, obj); listAttributeOrder.getSelectionModel().setSelectionInterval(iSelected + 1, iSelected + 1); }
From source file:org.nuclos.client.wizard.steps.NuclosEntitySQLLayoutStep.java
private void buttonUpAttributeAction() { int iSelected = listAttributeOrder.getSelectedIndex(); if (iSelected < 1 || iSelected > listAttributeOrder.getModel().getSize()) return;/* w ww. j ava 2 s . c o m*/ DefaultListModel model = (DefaultListModel) listAttributeOrder.getModel(); Object obj = model.remove(iSelected); model.add(iSelected - 1, obj); listAttributeOrder.getSelectionModel().setSelectionInterval(iSelected - 1, iSelected - 1); }