List of usage examples for javax.swing DefaultComboBoxModel removeElement
public void removeElement(Object anObject)
From source file:Main.java
public static void main(final String args[]) { final DefaultComboBoxModel<String> model = new DefaultComboBoxModel<String>(); model.addElement("A"); model.addElement("C"); model.addElement("D"); model.addElement("A"); model.removeElement("A"); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JComboBox<String> comboBox1 = new JComboBox<String>(model); comboBox1.setMaximumRowCount(5);/*from w ww .jav a2 s .c om*/ comboBox1.setEditable(true); frame.add(comboBox1, BorderLayout.NORTH); JList<String> jlist = new JList<String>(model); JScrollPane scrollPane = new JScrollPane(jlist); frame.add(scrollPane, BorderLayout.CENTER); JButton button = new JButton("Add"); frame.add(button, BorderLayout.SOUTH); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { model.addElement("a"); model.insertElementAt("Z", 0); } }; button.addActionListener(actionListener); frame.setSize(300, 200); frame.setVisible(true); }
From source file:paquete.HollywoodUI.java
private void btn_eliminarActorMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btn_eliminarActorMouseClicked Actor actor1 = (Actor) cb_list_eliminar.getSelectedItem(); Graph<Actor, Arista> tempGraph = HollyUniverseGraph; ArrayList<Arista> tempAristas = new ArrayList<Arista>(tempGraph.getInEdges(actor1)); actoresArray = new ArrayList<Actor>(tempGraph.getVertices()); for (int i = 0; i < actoresArray.size(); i++) { if (actoresArray.get(i).getNombre().equals(actor1.getNombre())) { actoresArray.remove(i);/*from ww w . j a v a2s .c o m*/ } } System.out.println("actores adyacntes"); ArrayList<Actor> tempActores2 = new ArrayList<Actor>(HollyUniverseGraph.getNeighbors(actor1)); for (int i = 0; i < tempActores2.size(); i++) { System.out.println(tempActores2.get(i).getNombre()); } System.out.println("actores array"); for (int i = 0; i < actoresArray.size(); i++) { System.out.println(actoresArray.get(i).getNombre()); } boolean existe = false; boolean eliminar = true; int existe1 = 0; for (int i = 0; i < actoresArray.size(); i++) { if (!actoresArray.get(i).equals(null)) { existe1 = i; } } ArrayList<Actor> tempActores = new ArrayList<Actor>(tempGraph.getNeighbors(actoresArray.get(0))); for (int i = 0; i < tempActores.size(); i++) { for (int j = 0; j < actoresArray.size(); j++) { if (tempActores.get(i).getNombre().equals(actoresArray.get(j).getNombre())) { existe = true; } } } if (actoresArray.size() > 2) { tempActores = new ArrayList<Actor>(tempGraph.getNeighbors(actoresArray.get(1))); for (int i = 0; i < tempActores.size(); i++) { for (int j = 0; j < actoresArray.size(); j++) { if (tempActores.get(i).getNombre().equals(actoresArray.get(j).getNombre())) { existe = true; } } } } if (actoresArray.size() > 3) { tempActores = new ArrayList<Actor>(tempGraph.getNeighbors(actoresArray.get(2))); for (int i = 0; i < tempActores.size(); i++) { for (int j = 0; j < actoresArray.size(); j++) { if (tempActores.get(i).getNombre().equals(actoresArray.get(j).getNombre())) { existe = true; } } } } if (actoresArray.size() > 4) { tempActores = new ArrayList<Actor>(tempGraph.getNeighbors(actoresArray.get(3))); for (int i = 0; i < tempActores.size(); i++) { for (int j = 0; j < actoresArray.size(); j++) { if (tempActores.get(i).getNombre().equals(actoresArray.get(j).getNombre())) { existe = true; } } } } tempAristas.clear(); if (existe) { HollyUniverseGraph.removeVertex(actor1); DefaultComboBoxModel cb_model = (DefaultComboBoxModel) cb_list_eliminar.getModel(); cb_model.removeElement(actor1); cb_list_eliminar.setModel(cb_model); JOptionPane.showMessageDialog(this.btn_eliminarActor, "Actor eliminado correctamente", "Informacion", JOptionPane.INFORMATION_MESSAGE); } else { JOptionPane.showMessageDialog(this.btn_eliminarActor, "El actor no se puede eliminar", "Informacion", JOptionPane.ERROR_MESSAGE); } actoresArray = new ArrayList<Actor>(HollyUniverseGraph.getVertices()); System.out.println("actializacion"); for (int i = 0; i < actoresArray.size(); i++) { System.out.println(actoresArray.get(i).getNombre()); } }
From source file:pl.otros.logview.gui.actions.search.SearchAction.java
public void performSearch(String text, SearchDirection direction) { StatusObserver statusObserver = getOtrosApplication().getStatusObserver(); JTabbedPane jTabbedPane = getOtrosApplication().getJTabbedPane(); LogViewPanelWrapper lvPanel = (LogViewPanelWrapper) jTabbedPane.getSelectedComponent(); if (lvPanel == null) { return;//w w w .java2 s .c o m } JTable table = lvPanel.getLogViewPanel().getTable(); NextRowProvider nextRowProvider = NextRowProviderFactory.getFilteredTableRow(table, direction); SearchContext context = new SearchContext(); context.setDataTableModel(lvPanel.getDataTableModel()); SearchMatcher searchMatcher = null; String confKey = null; if (SearchMode.STRING_CONTAINS.equals(searchMode)) { searchMatcher = new StringContainsSearchMatcher(text); confKey = ConfKeys.SEARCH_LAST_STRING; } else if (SearchMode.REGEX.equals(searchMode)) { try { searchMatcher = new RegexMatcher(text); confKey = ConfKeys.SEARCH_LAST_REGEX; } catch (Exception e) { statusObserver.updateStatus("Error in regular expression: " + e.getMessage(), StatusObserver.LEVEL_ERROR); return; } } else if (SearchMode.QUERY.equals(searchMode)) { QueryAcceptCondition acceptCondition; try { acceptCondition = new QueryAcceptCondition(text); searchMatcher = new AcceptConditionSearchMatcher(acceptCondition); confKey = ConfKeys.SEARCH_LAST_QUERY; } catch (RuleException e) { statusObserver.updateStatus("Wrong query rule: " + e.getMessage(), StatusObserver.LEVEL_ERROR); return; } } updateList(confKey, getOtrosApplication().getConfiguration(), text); DefaultComboBoxModel model = (DefaultComboBoxModel) getOtrosApplication().getSearchField().getModel(); model.removeElement(text); model.insertElementAt(text, 0); model.setSelectedItem(text); int maxCount = getOtrosApplication().getConfiguration().getInt(ConfKeys.SEARCH_LAST_COUNT, 30); while (model.getSize() > maxCount) { model.removeElementAt(model.getSize() - 1); } context.setSearchMatcher(searchMatcher); SearchResult searchNext = searchEngine.searchNext(context, nextRowProvider); if (searchNext.isFound()) { int row = table.convertRowIndexToView(searchNext.getRow()); Rectangle rect = table.getCellRect(row, 0, true); table.scrollRectToVisible(rect); table.clearSelection(); table.setRowSelectionInterval(row, row); statusObserver.updateStatus(String.format("Found at row %d", row), StatusObserver.LEVEL_NORMAL); if (markFound) { lvPanel.getDataTableModel().markRows(markerColors, table.convertRowIndexToModel(row)); } scrollToSearchResult( searchMatcher.getFoundTextFragments( lvPanel.getDataTableModel().getLogData(table.convertRowIndexToModel(row))), lvPanel.getLogViewPanel().getLogDetailTextArea()); } else { statusObserver.updateStatus(String.format("\"%s\" not found", text), StatusObserver.LEVEL_WARNING); } }