List of usage examples for javax.swing DefaultComboBoxModel addElement
public void addElement(E anObject)
From source file:SharedDataSample.java
public static void main(String args[]) { final String labels[] = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J" }; final DefaultComboBoxModel model = new DefaultComboBoxModel(labels); JFrame frame = new JFrame("Shared Data"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); JPanel panel = new JPanel(); JComboBox comboBox1 = new JComboBox(model); comboBox1.setMaximumRowCount(5);/*from ww w . j ava 2 s.c o m*/ comboBox1.setEditable(true); JComboBox comboBox2 = new JComboBox(model); comboBox2.setMaximumRowCount(5); comboBox2.setEditable(true); panel.add(comboBox1); panel.add(comboBox2); contentPane.add(panel, BorderLayout.NORTH); JList jlist = new JList(model); JScrollPane scrollPane = new JScrollPane(jlist); contentPane.add(scrollPane, BorderLayout.CENTER); JButton button = new JButton("Add"); contentPane.add(button, BorderLayout.SOUTH); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { int index = (int) (Math.random() * labels.length); model.addElement(labels[index]); } }; button.addActionListener(actionListener); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void initComboBoxModel(ComboBoxModel model, Object[] lista) { DefaultComboBoxModel defCombo = (DefaultComboBoxModel) model; defCombo.removeAllElements();/* w ww . j av a 2 s .c o m*/ for (Object o : lista) { defCombo.addElement(o); } }
From source file:Main.java
public static void initComboBoxModel(ComboBoxModel model, List lista) { DefaultComboBoxModel defCombo = (DefaultComboBoxModel) model; defCombo.removeAllElements();//ww w .j a v a 2 s . c om for (Object o : lista) { defCombo.addElement(o); } }
From source file:Main.java
/** * Setzt die Daten des Iterators in das ComboBoxModel. * /*from ww w. j a v a 2s .c o m*/ * @param comboBox {@link JComboBox} * @param iterator {@link Iterator} */ @SuppressWarnings("unchecked") public static void fillComboBox(final JComboBox<?> comboBox, final Iterator<?> iterator) { DefaultComboBoxModel<Object> comboBoxModel = (DefaultComboBoxModel<Object>) comboBox.getModel(); comboBoxModel.removeAllElements(); while (iterator.hasNext()) { comboBoxModel.addElement(iterator.next()); } }
From source file:Main.java
/** * Replace the options in a combo box with a new set. * nulls are skipped. Selected value is preserved. * * @param combob GUI component to update * @param values list of values to put into component, or null to erase *//*from ww w . j ava 2 s . c o m*/ public static void replaceContents(JComboBox combob, Object[] values) { Object cur = combob.getSelectedItem(); DefaultComboBoxModel m = (DefaultComboBoxModel) combob.getModel(); m.removeAllElements(); if (values != null) for (Object v : values) if (v != null) m.addElement(v); combob.setSelectedItem(cur); combob.setEnabled(true); }
From source file:Main.java
/** * Replace the options in a combo box with a new set. * nulls are skipped. Selected value is preserved. * * @param combob GUI component to update * @param values list of values to put into component, or null to erase *///from www.j av a 2 s .com public static void replaceContents(JComboBox combob, Vector<?> values) { Object cur = combob.getSelectedItem(); DefaultComboBoxModel m = (DefaultComboBoxModel) combob.getModel(); m.removeAllElements(); if (values != null) for (Object v : values) if (v != null) m.addElement(v); combob.setSelectedItem(cur); combob.setEnabled(true); }
From source file:Main.java
/** * Replace the options in a combo box with a new set. * nulls are skipped. Selected value is preserved. * * @param combob GUI component to update * @param values list of values to put into component, or null to erase *//*from w ww.j av a 2s. co m*/ public static void replaceContents(JComboBox combob, List<?> values) { Object cur = combob.getSelectedItem(); DefaultComboBoxModel m = (DefaultComboBoxModel) combob.getModel(); m.removeAllElements(); if (values != null) for (Object v : values) if (v != null) m.addElement(v); combob.setSelectedItem(cur); combob.setEnabled(true); }
From source file:eu.dety.burp.joseph.utilities.Converter.java
/** * Get RSA PublicKey by PublicKey HashMap input. Create a dialog popup with a combobox to choose the correct JWK to use. * // ww w.j av a 2s. c o m * @param publicKeys * HashMap containing a PublicKey and related describing string * @throws AttackPreparationFailedException * @return Selected {@link PublicKey} */ @SuppressWarnings("unchecked") public static PublicKey getRsaPublicKeyByJwkSelectionPanel(HashMap<String, PublicKey> publicKeys) throws AttackPreparationFailedException { // TODO: Move to other class? JPanel selectionPanel = new JPanel(); selectionPanel.setLayout(new java.awt.GridBagLayout()); GridBagConstraints constraints = new GridBagConstraints(); constraints.fill = GridBagConstraints.HORIZONTAL; constraints.gridy = 0; selectionPanel.add(new JLabel("Multiple JWKs found. Please choose one:"), constraints); JComboBox jwkSetKeySelection = new JComboBox<>(); DefaultComboBoxModel<String> jwkSetKeySelectionModel = new DefaultComboBoxModel<>(); for (Map.Entry<String, PublicKey> publicKey : publicKeys.entrySet()) { jwkSetKeySelectionModel.addElement(publicKey.getKey()); } jwkSetKeySelection.setModel(jwkSetKeySelectionModel); constraints.gridy = 1; selectionPanel.add(jwkSetKeySelection, constraints); int resultButton = JOptionPane.showConfirmDialog(null, selectionPanel, "Select JWK", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (resultButton == JOptionPane.CANCEL_OPTION) { throw new AttackPreparationFailedException("No JWK from JWK Set selected!"); } loggerInstance.log(Converter.class, "Key selected: " + jwkSetKeySelection.getSelectedIndex(), Logger.LogLevel.DEBUG); return publicKeys.get(jwkSetKeySelection.getSelectedItem()); }
From source file:jshm.gui.GuiUtil.java
public static void createSongCombo(JComboBox cb, List<? extends Song> songs) { cb.setRenderer(SONG_COMBO_RENDERER); DefaultComboBoxModel model = (DefaultComboBoxModel) cb.getModel(); model.removeAllElements();/*from w w w . j a va2 s . c om*/ model.addElement(SELECT_A_SONG); for (Song s : songs) model.addElement(s); AutoCompleteDecorator.decorate(cb, SONG_COMBO_CONVERTER); }
From source file:Main.java
void updateCombo() { DefaultComboBoxModel model = new DefaultComboBoxModel(); Random rnd = new Random(); for (int index = 0; index < 10 + rnd.nextInt(90); index++) { model.addElement(rnd.nextInt(1000)); }// w w w .j a v a 2s . co m comboBox.setModel(model); }