List of usage examples for javax.swing JComboBox removeItemAt
public void removeItemAt(int anIndex)
anIndex
This method works only if the JComboBox
uses a mutable data model. From source file:Main.java
public static void main(String[] argv) throws Exception { String[] items = { "item1", "item2" }; JComboBox cb = new JComboBox(items); cb.removeItemAt(cb.getItemCount() - 1); }
From source file:Main.java
public static void main(String[] argv) throws Exception { String[] items = { "item1", "item2" }; JComboBox cb = new JComboBox(items); cb.removeItemAt(0); }
From source file:org.forester.archaeopteryx.ControlPanel.java
public void setSequenceRelationQueries(final Collection<Sequence> sequenceRelationQueries) { final JComboBox box = getSequenceRelationBox(); while (box.getItemCount() > 1) { box.removeItemAt(1); }//from w w w .ja va 2 s . c o m final HashMap<String, Sequence> sequencesByName = new HashMap<String, Sequence>(); final SequenceRelation.SEQUENCE_RELATION_TYPE relationType = (SequenceRelation.SEQUENCE_RELATION_TYPE) _sequence_relation_type_box .getSelectedItem(); if (relationType == null) { return; } final ArrayList<String> sequenceNamesToAdd = new ArrayList<String>(); for (final Sequence seq : sequenceRelationQueries) { if (seq.hasSequenceRelations()) { boolean fFoundForCurrentType = false; for (final SequenceRelation sq : seq.getSequenceRelations()) { if (sq.getType().equals(relationType)) { fFoundForCurrentType = true; break; } } if (fFoundForCurrentType) { sequenceNamesToAdd.add(seq.getName()); sequencesByName.put(seq.getName(), seq); } } } // sort sequences by name before adding them to the combo final String[] sequenceNameArray = sequenceNamesToAdd.toArray(new String[sequenceNamesToAdd.size()]); Arrays.sort(sequenceNameArray, String.CASE_INSENSITIVE_ORDER); for (final String seqName : sequenceNameArray) { box.addItem(seqName); } for (final ItemListener oldItemListener : box.getItemListeners()) { box.removeItemListener(oldItemListener); } box.addItemListener(new ItemListener() { @Override public void itemStateChanged(final ItemEvent e) { _selected_query_seq = sequencesByName.get(e.getItem()); _mainpanel.getCurrentTreePanel().repaint(); } }); }
From source file:statemachinedesigner.EditorApplet.java
/** * create an instance of a simple graph with popup controls to * create a graph.//w w w . j av a2 s.c om * */ public EditorApplet(SimulatorController controller) { // create a simple graph for the demo _controller = controller; _graph = new DirectedSparseGraph<Number, Number>(); this.layout = new StaticLayout<Number, Number>(_graph, new Dimension(600, 600)); vv = new VisualizationViewer<Number, Number>(layout); vv.setBackground(Color.white); vv.getRenderContext().setVertexLabelTransformer(MapTransformer.<Number, String>getInstance( LazyMap.<Number, String>decorate(new HashMap<Number, String>(), new ToStringLabeller<Number>()))); vv.getRenderContext().setEdgeLabelTransformer(MapTransformer.<Number, String>getInstance( LazyMap.<Number, String>decorate(new HashMap<Number, String>(), new ToStringLabeller<Number>()))); vv.setVertexToolTipTransformer(vv.getRenderContext().getVertexLabelTransformer()); Container content = getContentPane(); final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv); content.add(panel); Factory<Number> vertexFactory = new VertexFactory(); Factory<Number> edgeFactory = new EdgeFactory(); final EditingModalGraphMouse<Number, Number> graphMouse = new EditingModalGraphMouse<Number, Number>( vv.getRenderContext(), vertexFactory, edgeFactory); // the EditingGraphMouse will pass mouse event coordinates to the // vertexLocations function to set the locations of the vertices as // they are created vv.setGraphMouse(graphMouse); vv.addKeyListener(graphMouse.getModeKeyListener()); graphMouse.setMode(ModalGraphMouse.Mode.EDITING); JButton submitButton = new JButton("Submit"); submitButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { LinkedList<Number> vertices = new LinkedList<Number>(); vertices.addAll(_graph.getVertices()); for (Number n : vertices) { if (_graph.getNeighborCount(n) == 0) { _graph.removeVertex(n); } } LinkedList<Number> edges = new LinkedList<Number>(); edges.addAll(_graph.getEdges()); for (Number n : edges) { if (_graph.getDest(n) == null) { _graph.removeEdge(n); } else if (_graph.getSource(n) == _graph.getDest(n)) { _graph.removeEdge(n); } } vv.repaint(); } }); JButton clearButton = new JButton("Clear All"); clearButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { //add code to clear all nodes vertexCount = 0; edgeCount = 0; LinkedList<Number> vertices = new LinkedList<Number>(); vertices.addAll(_graph.getVertices()); for (Number n : vertices) { _graph.removeVertex(n); } vv.repaint(); } }); JButton clearEdgesButton = new JButton("Clear All Edges"); clearEdgesButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { edgeCount = 0; LinkedList<Number> edges = new LinkedList<Number>(); edges.addAll(_graph.getEdges()); for (Number n : edges) { _graph.removeEdge(n); } vv.repaint(); } }); //to be removed JButton helpButton = new JButton("Help"); helpButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(vv, instructions); } }); JComboBox modeBox = graphMouse.getModeComboBox(); modeBox.removeItemAt(0); //transforming modeBox.removeItemAt(2); //annotating modeBox.setToolTipText( "Editing mode allows for insertion and removal of edges/vertices; Picking mode is for placement"); JPanel controlPanel = new JPanel(); controlPanel.add(new JLabel("Mouse Mode")); controlPanel.add(modeBox); controlPanel.add(submitButton); controlPanel.add(clearButton); controlPanel.add(clearEdgesButton); controlPanel.add(helpButton); content.add(controlPanel, BorderLayout.SOUTH); }