Java Code Examples for javax.swing.DefaultComboBoxModel#removeElementAt()
The following examples show how to use
javax.swing.DefaultComboBoxModel#removeElementAt() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GcViewSupport.java From visualvm with GNU General Public License v2.0 | 6 votes |
private void handleAggregationChanged(boolean updateSecondary) { if (updateSecondary) { DefaultComboBoxModel model = (DefaultComboBoxModel)secondCombo.getModel(); while (model.getSize() > 1) model.removeElementAt(1); // if (!Aggregation.CLASS.equals(firstCombo.getSelectedItem()) && // !Aggregation.CLASS_MESSAGE.equals(firstCombo.getSelectedItem())) // model.addElement(Aggregation.CLASS); // // if (!Aggregation.MESSAGE.equals(firstCombo.getSelectedItem()) && // !Aggregation.CLASS_MESSAGE.equals(firstCombo.getSelectedItem())) // model.addElement(Aggregation.MESSAGE); // // if (!Aggregation.CLASS.equals(firstCombo.getSelectedItem()) && // !Aggregation.MESSAGE.equals(firstCombo.getSelectedItem()) && // !Aggregation.CLASS_MESSAGE.equals(firstCombo.getSelectedItem())) // model.addElement(Aggregation.CLASS_MESSAGE); // // if (!Aggregation.THREAD.equals(firstCombo.getSelectedItem())) // model.addElement(Aggregation.THREAD); } updateButton.setEnabled(lastPrimary != firstCombo.getSelectedItem() || lastPhase != secondChoice.isSelected()); }
Example 2
Source File: SocketIOViewSupport.java From visualvm with GNU General Public License v2.0 | 6 votes |
private void handleAggregationChanged(boolean updateSecondary) { if (updateSecondary) { DefaultComboBoxModel model = (DefaultComboBoxModel)secondCombo.getModel(); while (model.getSize() > 1) model.removeElementAt(1); if (!Aggregation.ADDRESS.equals(firstCombo.getSelectedItem()) && !Aggregation.PORT.equals(firstCombo.getSelectedItem()) && !Aggregation.ADDRESS_PORT.equals(firstCombo.getSelectedItem())) model.addElement(Aggregation.ADDRESS_PORT); if (!Aggregation.ADDRESS.equals(firstCombo.getSelectedItem()) && !Aggregation.ADDRESS_PORT.equals(firstCombo.getSelectedItem())) model.addElement(Aggregation.ADDRESS); if (!Aggregation.PORT.equals(firstCombo.getSelectedItem()) && !Aggregation.ADDRESS_PORT.equals(firstCombo.getSelectedItem())) model.addElement(Aggregation.PORT); if (!Aggregation.THREAD.equals(firstCombo.getSelectedItem())) model.addElement(Aggregation.THREAD); } updateButton.setEnabled(lastPrimary != firstCombo.getSelectedItem() || lastSecondary != secondCombo.getSelectedItem()); }
Example 3
Source File: GUIUtils.java From open-ig with GNU Lesser General Public License v3.0 | 6 votes |
/** * Checks if the item is in the combobox. If yes, then it is moved to the beginning, * otherwise, the item is added as first. * @param <T> the element type * @param combobox the combobox * @param item the item */ public static <T> void addFirstItem(JComboBox<T> combobox, T item) { int idx = -1; DefaultComboBoxModel<T> model = (DefaultComboBoxModel<T>)combobox.getModel(); for (int i = 0; i < model.getSize(); i++) { T t = model.getElementAt(i); if (Objects.equals(t, item)) { idx = i; break; } } model.insertElementAt(item, 0); if (idx >= 0) { model.removeElementAt(idx + 1); } }
Example 4
Source File: SummaryTablePanel.java From nmonvisualizer with Apache License 2.0 | 6 votes |
private void updateStatisticsComboBox() { String newName = Statistic.GRANULARITY_MAXIMUM.getName(gui.getGranularity()); @SuppressWarnings("unchecked") DefaultComboBoxModel<Object> model = (DefaultComboBoxModel<Object>) ((JComboBox<Object>) statsPanel .getComponent(1)).getModel(); boolean reselect = false; if (model.getSelectedItem() == model.getElementAt(4)) { reselect = true; } model.removeElementAt(4); model.insertElementAt(newName, 4); if (reselect) { model.setSelectedItem(newName); } }
Example 5
Source File: ColorComboBox.java From netbeans with Apache License 2.0 | 5 votes |
private void removeCustomValue() { for( int i=0; i<getItemCount(); i++ ) { ColorValue cv = ( ColorValue ) getItemAt( i ); if( cv.isCustom ) { DefaultComboBoxModel model = ( DefaultComboBoxModel ) getModel(); model.removeElementAt( i ); return; } } }
Example 6
Source File: DirectorySelectorCombo.java From netbeans with Apache License 2.0 | 5 votes |
private ComboListElement addPath(String path) { DefaultComboBoxModel model = (DefaultComboBoxModel)fileMRU.getModel(); ComboListElement newPath = new StringComboListElement(path); int index = model.getIndexOf(newPath); if (index == -1) { model.insertElementAt(newPath, 1); } if (model.getSize() > itemCountLimit + 3) { model.removeElementAt(model.getSize() - 3); } return newPath; }
Example 7
Source File: ExceptionsViewSupport.java From visualvm with GNU General Public License v2.0 | 5 votes |
private void handleAggregationChanged(boolean updateSecondary) { if (updateSecondary) { DefaultComboBoxModel model = (DefaultComboBoxModel)secondCombo.getModel(); while (model.getSize() > 1) model.removeElementAt(1); if (!Aggregation.CLASS.equals(firstCombo.getSelectedItem()) && !Aggregation.CLASS_MESSAGE.equals(firstCombo.getSelectedItem())) model.addElement(Aggregation.CLASS); if (!Aggregation.MESSAGE.equals(firstCombo.getSelectedItem()) && !Aggregation.CLASS_MESSAGE.equals(firstCombo.getSelectedItem())) model.addElement(Aggregation.MESSAGE); if (!Aggregation.CLASS.equals(firstCombo.getSelectedItem()) && !Aggregation.MESSAGE.equals(firstCombo.getSelectedItem()) && !Aggregation.CLASS_MESSAGE.equals(firstCombo.getSelectedItem())) model.addElement(Aggregation.CLASS_MESSAGE); if (!Aggregation.THREAD.equals(firstCombo.getSelectedItem())) model.addElement(Aggregation.THREAD); } updateButton.setEnabled(lastMode != modeCombo.getSelectedIndex() || lastPrimary != firstCombo.getSelectedItem() || lastSecondary != secondCombo.getSelectedItem()); }
Example 8
Source File: LocksViewSupport.java From visualvm with GNU General Public License v2.0 | 5 votes |
private void handleAggregationChanged(boolean updateSecondary) { if (updateSecondary) { int sel = secondCombo.getSelectedIndex(); DefaultComboBoxModel model = (DefaultComboBoxModel)secondCombo.getModel(); while (model.getSize() > 1) model.removeElementAt(1); if (!Aggregation.CLASS.equals(firstCombo.getSelectedItem()) && !Aggregation.OBJECT.equals(firstCombo.getSelectedItem())) model.addElement(Aggregation.CLASS); if (!Aggregation.CLASS.equals(firstCombo.getSelectedItem()) && !Aggregation.OBJECT.equals(firstCombo.getSelectedItem())) model.addElement(Aggregation.OBJECT); if (!Aggregation.THREAD_BLOCKED.equals(firstCombo.getSelectedItem())) model.addElement(Aggregation.THREAD_BLOCKED); if (!Aggregation.THREAD_BLOCKING.equals(firstCombo.getSelectedItem())) model.addElement(Aggregation.THREAD_BLOCKING); secondCombo.setSelectedIndex(sel < secondCombo.getItemCount() ? sel : 0); } updateButton.setEnabled(lastMode != modeCombo.getSelectedIndex() || lastPrimary != firstCombo.getSelectedItem() || lastSecondary != secondCombo.getSelectedItem()); }
Example 9
Source File: DemoUtils.java From java-ocr-api with GNU Affero General Public License v3.0 | 5 votes |
public static void savePrefs(Preferences prefs, String prefKey, JComboBox combo, String newValidValue) { if (newValidValue == null) { return; } DefaultComboBoxModel comboModel = (DefaultComboBoxModel) combo.getModel(); int existingIndex = comboModel.getIndexOf(newValidValue); if (existingIndex >= 0) { comboModel.removeElementAt(existingIndex); } comboModel.insertElementAt(newValidValue, 0); combo.setSelectedIndex(0); StringBuilder entries = new StringBuilder(); int size = Math.min(comboModel.getSize(), 20); for (int i = 0; i < size; i++) { entries.append(comboModel.getElementAt(i)); if (i != size - 1) { entries.append(DELIMITER); } } while (entries.length() > Preferences.MAX_VALUE_LENGTH) { int lastIndex = entries.lastIndexOf(DELIMITER); if (lastIndex == -1) { break; } else { entries.delete(lastIndex, entries.length()); } } prefs.put(prefKey, entries.toString()); try { prefs.flush(); } catch (Throwable e) { e.printStackTrace(); } }