List of usage examples for javax.swing DefaultListModel addElement
public void addElement(E element)
From source file:org.nbgames.core.PlayerManager.java
public DefaultListModel load(DefaultListModel model) { model.clear();//w w w . j a v a 2 s.com load(); for (Player player : mPlayers) { model.addElement(player); } return model; }
From source file:org.netbeans.modules.php.fuel.options.FuelPhpOptionsPanel.java
private void setAvailableNodes() { DefaultListModel<String> defaultListModel = new DefaultListModel<String>(); for (String node : FuelPhp.CUSTOM_NODES) { defaultListModel.addElement(node); }//from ww w .j ava 2 s.c om nodeList.setModel(defaultListModel); List<String> availableNodes = FuelPhpOptions.getInstance().getAvailableNodes(); for (String node : availableNodes) { int indexOf = defaultListModel.indexOf(node); nodeList.addSelectionInterval(indexOf, indexOf); } }
From source file:org.nuclos.client.wizard.steps.NuclosEntitySQLLayoutStep.java
@Override public void prepare() { this.setComplete(true); mpFieldNameChanged = new HashMap<String, String>(); if (this.model.getAttributeModel().getAttributes().size() == 0) cbLayout.setEnabled(false);/*w ww.ja v a 2 s . c o m*/ else cbLayout.setEnabled(true); hasEntityLayout = hasEntityLayout(); if (hasEntityLayout) { lbLayout.setText(SpringLocaleDelegate.getInstance().getMessage("wizard.step.entitysqllayout.16", "Wollen Sie die bestehende Maske aktualisieren:")); } DefaultListModel listmodel = new DefaultListModel(); List<Attribute> lstAttr = new ArrayList<Attribute>(this.model.getAttributeModel().getAttributes()); for (Attribute attr : lstAttr) { listmodel.addElement(attr); } treeModel = new MyTreeModel(model.getAttributeModel().getAttributeMap()); try { treeAttributeOrder.setModel(treeModel); treeModel.expandWholeTree(); } // TODO: Avoid this NPE (tp) catch (NullPointerException e) { LOG.info("prepare failed: " + e); } catch (Exception e) { LOG.info("prepare failed: " + e, e); } listAttributeOrder.setModel(listmodel); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { try { validateEntity(); } catch (CommonValidationException ex) { NuclosEntitySQLLayoutStep.this.setComplete(false); Errors.getInstance().showExceptionDialog(NuclosEntitySQLLayoutStep.this, ex); } } }); }
From source file:org.opendatakit.briefcase.ui.CharsetConverterDialog.java
protected void initialize() { DefaultListModel<CharsetEntry> defaultListModel = new DefaultListModel<CharsetEntry>(); for (CharsetEntry commonCharsetEntry : commonCharsetEntries) { try {// w ww .j a va2s . c o m if (Charset.isSupported(commonCharsetEntry.getCharsetName())) { defaultListModel.addElement(commonCharsetEntry); } } catch (IllegalCharsetNameException e) { // just ignore it. It will happen for "Mac OS Roman" under Windows } } SortedMap<String, Charset> charsetSortedMap = Charset.availableCharsets(); for (Map.Entry<String, Charset> charsetMapEntry : charsetSortedMap.entrySet()) { CharsetEntry charsetEntry = new CharsetEntry(charsetMapEntry.getValue().displayName(), charsetMapEntry.getKey()); if (!defaultListModel.contains(charsetEntry)) { defaultListModel.addElement(charsetEntry); } } listCharset.setModel(defaultListModel); if (defaultListModel.size() > 0) { listCharset.setSelectedIndex(0); listCharset.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { updatePreview(); } }); } else { JOptionPane.showMessageDialog(this, "It appears that your installed Java Runtime Environment does not support any charset encodings!", "Error!", JOptionPane.ERROR_MESSAGE); } }
From source file:org.openestate.tool.helloworld.HelloWorldFrameSidebarExtension.java
public static DefaultListModel<DbHelloWorldObject> createListModel(Connection c, DbHelloWorldHandler dbHelloWorldHandler) throws SQLException { DefaultListModel<DbHelloWorldObject> model = new DefaultListModel<>(); for (DbHelloWorldObject object : dbHelloWorldHandler.getObjects(c)) { model.addElement(object); }/* ww w .ja va 2s . c o m*/ return model; }
From source file:org.openmicroscopy.shoola.agents.measurement.util.ui.ResultsCellRenderer.java
/** * Creates and returns a {@link JList} from the passed object. * /*from w w w .j av a 2 s.c o m*/ * @param value The object to handle. * @return See above. */ private JList createList(Object value) { List elementList = (List) value; JList list = new JList(); DefaultListModel model = new DefaultListModel(); String v; for (Object element : elementList) { if (element instanceof Float) { v = twoDecimalPlaces((Float) element); if (v == null) return list; model.addElement(v); } else if (element instanceof Double) { v = twoDecimalPlaces((Double) element); if (v == null) return list; model.addElement(v); } } list.setModel(model); return list; }
From source file:org.openmrs.module.muzimabiometrics.panels.ScanFingerprint.java
private boolean SearchDevice() { DefaultListModel model = (DefaultListModel) scannerList.getModel(); model.clear();// w ww. j a v a 2 s .c o m for (NDevice device : deviceManager.getDevices()) { model.addElement(device); } NFingerScanner scanner = (NFingerScanner) FingersTools.getInstance().getClient().getFingerScanner(); if ((scanner == null) && (model.getSize() > 0)) { scannerList.setSelectedIndex(0); return true; } else if (scanner != null) { scannerList.setSelectedValue(scanner, true); return true; } return false; }
From source file:org.openuat.apps.BedaApp.java
private void updateDeviceList() { devices = peerManager.getPeers();/*from w ww. jav a 2 s.c o m*/ DefaultListModel listModel = new DefaultListModel(); for (RemoteDevice device : devices) { try { listModel.addElement(device.getFriendlyName(false)); } catch (IOException e) { listModel.addElement("Unknown device"); } } deviceList.setModel(listModel); }
From source file:org.shaman.rpg.editor.dialog.DialogVisualElement.java
private void setupVisuals() { isInsideSetupVisuals = true;//from ww w . j a v a2 s.c om LOG.info("setup visuals"); contentPanel.removeAll(); commandPanels.clear(); //load dialog dialog = obj.load(); if (dialog == null) { contentPanel.add(new JLabel("unable to load the dialog")); isInsideSetupVisuals = false; return; } EditableProperties editableProperties = null; try { editableProperties = obj.getResourceBundle(); } catch (IOException ex) { LOG.log(Level.WARNING, "unable to load properties file", ex); } //set header nameTextField.getDocument().removeUndoableEditListener(undoRedo); nameTextField.setText(dialog.getName()); nameTextField.getDocument().addUndoableEditListener(undoRedo); String[] persons = dialog.getPersonList(); @SuppressWarnings("unchecked") DefaultListModel<String> listModel = (DefaultListModel<String>) personsList.getModel(); listModel.clear(); listModel.ensureCapacity(persons.length); for (String p : persons) { listModel.addElement(p); } personsList.clearSelection(); //set commands for (Command c : dialog.getCommands()) { CommandPanel p = null; if (c instanceof TextType) { p = new TextTypePanel(); } else if (c instanceof StopType) { p = new StopTypePanel(); } else if (c instanceof SetvarType) { p = new SetVarTypePanel(); } else if (c instanceof AddvarType) { p = new AddVarTypePanel(); } else if (c instanceof IfType) { p = new IfTypePanel(); } else if (c instanceof LabelType) { p = new LabelTypePanel(); } else if (c instanceof GotoType) { p = new GotoTypePanel(); } else if (c instanceof QuestionType) { p = new QuestionTypePanel(); } else { LOG.info("unknown command: " + c); continue; } p.setVisualElement(this); p.setDialog(dialog); p.setCommand(c); if (editableProperties != null) { p.updateResourceBundle(editableProperties, false); } p.setUndoRedo(undoRedo); contentPanel.add(p); commandPanels.add(p); } repaint(); recursiveValidate(contentPanel); repaint(); recursiveValidate(contentPanel); EventQueue.invokeLater(new Runnable() { @Override public void run() { recursiveValidate(contentPanel); contentPanel.repaint(); } }); isInsideSetupVisuals = false; }
From source file:org.shaman.rpg.editor.dialog.DialogVisualElement.java
private void updatePersons() { if (isInsideSetupVisuals) { return;//from w ww .j a va2 s . co m } //Extract persons @SuppressWarnings("unchecked") final DefaultListModel<String> listModel = (DefaultListModel<String>) personsList.getModel(); final String[] newPersons = new String[listModel.size()]; listModel.copyInto(newPersons); LOG.info("settings persons to " + Arrays.toString(newPersons)); final String[] oldPersons = dialog.getPersonList(); //send to dialog dialog.setPersonList(newPersons); updateDialogPersons(); // undo/redo undoRedo.undoableEditHappened(new UndoableEditEvent(dialog, new AbstractUndoableEdit() { @Override public void undo() throws CannotUndoException { super.undo(); isInsideSetupVisuals = true; listModel.clear(); listModel.ensureCapacity(oldPersons.length); for (String s : oldPersons) { listModel.addElement(s); } LOG.info("settings persons to " + Arrays.toString(oldPersons)); dialog.setPersonList(oldPersons); updateDialogPersons(); isInsideSetupVisuals = false; } @Override public void redo() throws CannotRedoException { super.redo(); isInsideSetupVisuals = true; listModel.clear(); listModel.ensureCapacity(newPersons.length); for (String s : newPersons) { listModel.addElement(s); } LOG.info("settings persons to " + Arrays.toString(newPersons)); dialog.setPersonList(newPersons); updateDialogPersons(); isInsideSetupVisuals = false; } })); }