Example usage for javax.swing JComboBox setSelectedItem

List of usage examples for javax.swing JComboBox setSelectedItem

Introduction

In this page you can find the example usage for javax.swing JComboBox setSelectedItem.

Prototype

@BeanProperty(bound = false, preferred = true, description = "Sets the selected item in the JComboBox.")
public void setSelectedItem(Object anObject) 

Source Link

Document

Sets the selected item in the combo box display area to the object in the argument.

Usage

From source file:com.liveperson.infra.akka.actorx.ui.DisplayGraph.java

public static JPanel getGraphPanel() {

    final VisualizationViewer<String, String> vv = new VisualizationViewer<String, String>(new FRLayout(graph));

    vv.setBackground(Color.white);

    vv.getRenderContext().setVertexFillPaintTransformer(
            new PickableVertexPaintTransformer<String>(vv.getPickedVertexState(), Color.blue, Color.yellow));
    vv.getRenderContext().setVertexLabelTransformer(new Transformer<String, String>() {
        @Override//from  w  ww  .  ja v a  2 s  . c o m
        public String transform(String s) {
            return getClassName(s);
        }
    });
    vv.setVertexToolTipTransformer(new Transformer<String, String>() {
        @Override
        public String transform(String s) {
            return getClassName(s);
        }
    });

    vv.getRenderContext().setEdgeDrawPaintTransformer(
            new PickableEdgePaintTransformer<String>(vv.getPickedEdgeState(), Color.black, Color.green));
    vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.QuadCurve<String, String>());
    vv.setEdgeToolTipTransformer(new Transformer<String, String>() {
        @Override
        public String transform(String edge) {
            StringBuffer buffer = new StringBuffer();
            buffer.append("<html>");
            int index = edge.indexOf(Main.DELIMITER);
            String fromActor = edge.substring(0, index);
            String toActor = edge.substring(index + Main.DELIMITER.length());
            Map<String, Set<String>> connections = castConnectionList.get(fromActor);
            Set<String> messages = connections.get(toActor);
            for (String msg : messages) {
                buffer.append("<p>").append(getClassName(msg));
            }
            buffer.append("</html>");
            return buffer.toString();
        }
    });
    ToolTipManager.sharedInstance().setDismissDelay(60000);

    final DefaultModalGraphMouse<String, String> graphMouse = new DefaultModalGraphMouse<String, String>();
    graphMouse.setMode(ModalGraphMouse.Mode.PICKING);
    vv.setGraphMouse(graphMouse);

    final ScalingControl scaler = new CrossoverScalingControl();

    JButton plus = new JButton("+");
    plus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1.1f, vv.getCenter());
        }
    });
    JButton minus = new JButton("-");
    minus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1 / 1.1f, vv.getCenter());
        }
    });
    JButton reset = new JButton("reset");
    reset.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Layout<String, String> layout = vv.getGraphLayout();
            layout.initialize();
            Relaxer relaxer = vv.getModel().getRelaxer();
            if (relaxer != null) {
                //            if(layout instanceof IterativeContext) {
                relaxer.stop();
                relaxer.prerelax();
                relaxer.relax();
            }
        }
    });

    JPanel jp = new JPanel();
    jp.setBackground(Color.WHITE);
    jp.setLayout(new BorderLayout());
    jp.add(vv, BorderLayout.CENTER);
    Class[] combos = getCombos();
    final JComboBox jcb = new JComboBox(combos);
    // use a renderer to shorten the layout name presentation
    jcb.setRenderer(new DefaultListCellRenderer() {
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
                boolean cellHasFocus) {
            String valueString = value.toString();
            valueString = valueString.substring(valueString.lastIndexOf('.') + 1);
            return super.getListCellRendererComponent(list, valueString, index, isSelected, cellHasFocus);
        }
    });
    jcb.addActionListener(new LayoutChooser(jcb, vv));
    jcb.setSelectedItem(FRLayout.class);

    JPanel control_panel = new JPanel(new GridLayout(2, 1));
    JPanel topControls = new JPanel();
    JPanel bottomControls = new JPanel();
    control_panel.add(topControls);
    control_panel.add(bottomControls);
    jp.add(control_panel, BorderLayout.NORTH);

    topControls.add(jcb);
    bottomControls.add(plus);
    bottomControls.add(minus);
    bottomControls.add(reset);
    return jp;
}

From source file:bigdata.explorer.nutch.grapview.ShowLayouts.java

private static JPanel getGraphPanel() throws IOException {
    g_array = (Graph<? extends Object, ? extends Object>[]) new Graph<?, ?>[graph_names.length];

    Factory<Graph<Integer, Number>> graphFactory = new Factory<Graph<Integer, Number>>() {
        public Graph<Integer, Number> create() {
            return new SparseMultigraph<Integer, Number>();
        }/* www.j a va 2s  . com*/
    };

    Factory<Integer> vertexFactory = new Factory<Integer>() {
        int count;

        public Integer create() {
            return count++;
        }
    };
    Factory<Number> edgeFactory = new Factory<Number>() {
        int count;

        public Number create() {
            return count++;
        }
    };

    g_array[0] = TestGraphs.createTestGraph(false);
    g_array[1] = MixedRandomGraphGenerator.generateMixedRandomGraph(graphFactory, vertexFactory, edgeFactory,
            new HashMap<Number, Number>(), 20, true, new HashSet<Integer>());
    g_array[2] = TestGraphs.getDemoGraph();
    g_array[3] = TestGraphs.createDirectedAcyclicGraph(4, 4, 0.3);
    g_array[4] = TestGraphs.getOneComponentGraph();
    g_array[5] = TestGraphs.createChainPlusIsolates(18, 5);
    g_array[6] = TestGraphs.createChainPlusIsolates(0, 20);

    g_array[7] = NutchGraphLoader.loadFullGraph("/home/kamir/ANALYSIS/Nutch/YellowMED_CORE");

    Graph<? extends Object, ? extends Object> g = g_array[4]; // initial graph

    final VisualizationViewer<Integer, Number> vv = new VisualizationViewer<Integer, Number>(new FRLayout(g));

    vv.getRenderContext().setVertexFillPaintTransformer(
            new PickableVertexPaintTransformer<Integer>(vv.getPickedVertexState(), Color.red, Color.yellow));

    final DefaultModalGraphMouse<Integer, Number> graphMouse = new DefaultModalGraphMouse<Integer, Number>();
    vv.setGraphMouse(graphMouse);

    final ScalingControl scaler = new CrossoverScalingControl();

    JButton plus = new JButton("+");
    plus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1.1f, vv.getCenter());
        }
    });
    JButton minus = new JButton("-");
    minus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1 / 1.1f, vv.getCenter());
        }
    });
    JButton reset = new JButton("reset");
    reset.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Layout<Integer, Number> layout = vv.getGraphLayout();
            layout.initialize();
            Relaxer relaxer = vv.getModel().getRelaxer();
            if (relaxer != null) {
                //            if(layout instanceof IterativeContext) {
                relaxer.stop();
                relaxer.prerelax();
                relaxer.relax();
            }
        }
    });

    JComboBox modeBox = graphMouse.getModeComboBox();
    modeBox.addItemListener(((DefaultModalGraphMouse<Integer, Number>) vv.getGraphMouse()).getModeListener());

    JPanel jp = new JPanel();
    jp.setBackground(Color.WHITE);
    jp.setLayout(new BorderLayout());
    jp.add(vv, BorderLayout.CENTER);
    Class[] combos = getCombos();
    final JComboBox jcb = new JComboBox(combos);
    // use a renderer to shorten the layout name presentation
    jcb.setRenderer(new DefaultListCellRenderer() {
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
                boolean cellHasFocus) {
            String valueString = value.toString();
            valueString = valueString.substring(valueString.lastIndexOf('.') + 1);
            return super.getListCellRendererComponent(list, valueString, index, isSelected, cellHasFocus);
        }
    });
    jcb.addActionListener(new LayoutChooser(jcb, vv));
    jcb.setSelectedItem(FRLayout.class);

    JPanel control_panel = new JPanel(new GridLayout(2, 1));
    JPanel topControls = new JPanel();
    JPanel bottomControls = new JPanel();
    control_panel.add(topControls);
    control_panel.add(bottomControls);
    jp.add(control_panel, BorderLayout.NORTH);

    final JComboBox graph_chooser = new JComboBox(graph_names);

    graph_chooser.addActionListener(new GraphChooser(jcb));

    topControls.add(jcb);
    topControls.add(graph_chooser);
    bottomControls.add(plus);
    bottomControls.add(minus);
    bottomControls.add(modeBox);
    bottomControls.add(reset);
    return jp;
}

From source file:com.eviware.soapui.impl.rest.panels.request.RestRequestDesktopPanel.java

private JPanel addMethodCombo() {
    JPanel methodPanel = new JPanel(new BorderLayout());
    JComboBox methodComboBox = new JComboBox(new RestRequestMethodModel(getRequest()));
    methodComboBox.setSelectedItem(getRequest().getMethod());

    JLabel methodLabel = new JLabel("Method");
    methodPanel.add(methodLabel, BorderLayout.NORTH);
    methodPanel.add(methodComboBox, BorderLayout.SOUTH);
    methodPanel.setMinimumSize(new Dimension(75, STANDARD_TOOLBAR_HEIGHT));
    methodPanel.setMaximumSize(new Dimension(75, STANDARD_TOOLBAR_HEIGHT + 10));
    return methodPanel;
}

From source file:cool.pandora.modeller.ui.BagTableFormBuilder.java

/**
 * addList.//from  w  w  w  .ja  v  a  2 s. c om
 *
 * @param isRequired   boolean
 * @param label        String
 * @param elements     Collection
 * @param defaultValue String
 * @param checkbox     JComponent
 * @return addBinding
 */
public JComponent[] addList(final boolean isRequired, final String label, final Collection<String> elements,
        final String defaultValue, final JComponent checkbox) {
    final ArrayList<String> listModel = new ArrayList<>();
    listModel.addAll(elements);

    // Set default value selected from value list
    final JComboBox<String> dropDownTextField = new JComboBox<>(
            listModel.toArray(new String[listModel.size()]));
    dropDownTextField.setSelectedItem(defaultValue);
    final Object obj = dropDownTextField.getSelectedItem();
    dropDownTextField.setSelectedItem(obj);

    return addBinding(isRequired, label, dropDownTextField, checkbox);
}

From source file:com.eviware.soapui.impl.rest.panels.mock.RestMockResponseDesktopPanel.java

private JComboBox createStatusCodeCombo() {
    ComboBoxModel httpStatusCodeComboBoxModel = new HttpStatusCodeComboBoxModel();

    final JComboBox statusCodeCombo = new JComboBox(httpStatusCodeComboBoxModel);

    statusCodeCombo.setSelectedItem(CompleteHttpStatus.from(getModelItem().getResponseHttpStatus()));
    statusCodeCombo.setToolTipText("Set desired HTTP status code");
    statusCodeCombo.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            getModelItem().setResponseHttpStatus(
                    ((CompleteHttpStatus) statusCodeCombo.getSelectedItem()).getStatusCode());
        }//  www  . jav  a2 s .  c om
    });
    return statusCodeCombo;
}

From source file:es.emergya.ui.plugins.forms.FormGeneric.java

protected void addComboBox(Object selected, Object[] options, String title) {
    rows++;//from   ww  w . jav  a 2s  .c  o m
    mid.add(new JLabel(i18n.getString(title), JLabel.RIGHT));
    JComboBox cb = new JComboBox(options);
    cb.setSelectedItem(selected);
    cb.setName(title);
    componentes.add(cb);
    mid.add(cb);
    for (int i = 2; i < cols; i++)
        mid.add(Box.createHorizontalGlue());
}

From source file:projects.tgas.exec.HrDiagram.java

/**
 * Main constructor.// ww w.  j  a va2  s  .c  o  m
 */
public HrDiagram() {

    tgasStars = TgasUtils.loadTgasCatalogue();

    method = METHOD.NAIVE;
    fMax = 1.0;

    final JComboBox<METHOD> methodComboBox = new JComboBox<METHOD>(METHOD.values());
    methodComboBox.setSelectedItem(method);
    methodComboBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            method = (METHOD) methodComboBox.getSelectedItem();
            updateChart();
        }
    });

    final JSlider fSlider = GuiUtil.buildSlider(0.0, 2.0, 5, "%3.3f");
    fSlider.setValue((int) Math.rint(100.0 * fMax / 2.0));
    final JLabel fLabel = new JLabel(getFLabel());
    // Create a change listener fot these
    ChangeListener cl = new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            JSlider source = (JSlider) e.getSource();

            if (source == fSlider) {
                // Compute fractional parallax error from slider position
                double newF = (2.0 * source.getValue() / 100.0);
                fMax = newF;
                fLabel.setText(getFLabel());
            }
            updateChart();
        }
    };
    fSlider.addChangeListener(cl);
    // Add a bit of padding to space things out
    fSlider.setBorder(new EmptyBorder(5, 5, 5, 5));

    // Present controls below the HR diagram
    JPanel controls = new JPanel(new GridLayout(2, 2));
    controls.add(new JLabel("Distance estimation method:"));
    controls.add(methodComboBox);
    controls.add(fLabel);
    controls.add(fSlider);

    // Initialise the ChartPanel
    updateChart();

    // Build the panel contents
    setLayout(new BorderLayout());
    add(hrDiagPanel, BorderLayout.CENTER);
    add(controls, BorderLayout.SOUTH);
}

From source file:es.emergya.ui.gis.popups.GenericDialog.java

protected void addComboBox(Object selected, Object[] options, String title) {
    rows++;//from w w w .j av  a 2  s .  com
    mid.add(new JLabel(i18n.getString(title), JLabel.RIGHT));
    JComboBox cb = new JComboBox(options);
    cb.setName(title);
    cb.setSelectedItem(selected);
    mid.add(cb);
    componentes.add(cb);
    for (int i = 2; i < cols; i++)
        mid.add(Box.createHorizontalGlue());
}

From source file:com.eviware.soapui.support.editor.inspectors.auth.ExpirationTimeChooser.java

private JComboBox createTimeUnitCombo(boolean enableManualTimeControls) {
    JComboBox timeUnitCombo = new JComboBox(TIME_UNIT_OPTIONS);
    timeUnitCombo.setName(TIME_UNIT_COMBO_NAME);
    timeUnitCombo.setEnabled(enableManualTimeControls);

    TimeUnitConfig.Enum timeUnit = profile.getManualAccessTokenExpirationTimeUnit();
    timeUnitCombo.setSelectedItem(WordUtils.capitalize(timeUnit.toString().toLowerCase()));

    return timeUnitCombo;
}

From source file:com.game.ui.views.PlayerEditor.java

@Override
public void actionPerformed(ActionEvent ae) {
    validationMess.setText("");
    validationMess.setVisible(false);/*from   w  w  w. jav  a2  s  .c  o m*/
    if (ae.getActionCommand().equalsIgnoreCase("dropDown")) {
        JComboBox comboBox = (JComboBox) ae.getSource();
        String type = comboBox.getSelectedItem().toString();
        for (GameCharacter user : GameBean.playerDetails) {
            Player player = (Player) user;
            if (player.getType().equalsIgnoreCase(type)) {
                ((JTextField) leftPanel.getComponent(2)).setText(player.getName());
                ((JTextField) leftPanel.getComponent(4)).setText(player.getImagePath());
                ((JTextField) leftPanel.getComponent(6)).setText(new Integer(player.getHealth()).toString());
                ((JTextField) leftPanel.getComponent(8)).setText(new Integer(player.getAttackPts()).toString());
                ((JTextField) leftPanel.getComponent(10)).setText(new Integer(player.getArmor()).toString());
                ((JTextField) leftPanel.getComponent(12))
                        .setText(new Integer(player.getAttackRange()).toString());
                ((JTextField) leftPanel.getComponent(14)).setText(new Integer(player.getMovement()).toString());
                ((JTextField) leftPanel.getComponent(16)).setText(player.getType());
                JComboBox cBox = (JComboBox) leftPanel.getComponent(18);
                cBox.setSelectedItem(player.getInventory().getEquippedWeapon().getName());
                lvlPanel.txtFields[0].setText("" + player.getLevel());
                lvlPanel.txtFields[1].setText("" + player.getExp());
                lvlPanel.txtFields[2].setText("" + player.getStrength());
                lvlPanel.txtFields[3].setText("" + player.getVitality());
                lvlPanel.txtFields[4].setText("" + player.getDexterity());
                lvlPanel.txtFields[5].setText("" + player.getWisdom());
                break;
                //                    return;
            }
        }
    } else {
        String name = ((JTextField) leftPanel.getComponent(2)).getText();
        String image = ((JTextField) leftPanel.getComponent(4)).getText();
        String health = ((JTextField) leftPanel.getComponent(6)).getText();
        String attackPts = ((JTextField) leftPanel.getComponent(8)).getText();
        String armourPts = ((JTextField) leftPanel.getComponent(10)).getText();
        String attackRnge = ((JTextField) leftPanel.getComponent(12)).getText();
        String movement = ((JTextField) leftPanel.getComponent(14)).getText();
        String type = ((JTextField) leftPanel.getComponent(16)).getText();
        String weapon = ((JComboBox) leftPanel.getComponent(18)).getSelectedItem().toString();
        int attr[] = new int[6];
        attr[0] = Integer.parseInt(lvlPanel.txtFields[0].getText());
        attr[1] = Integer.parseInt(lvlPanel.txtFields[1].getText());
        attr[2] = Integer.parseInt(lvlPanel.txtFields[2].getText());
        attr[3] = Integer.parseInt(lvlPanel.txtFields[3].getText());
        attr[4] = Integer.parseInt(lvlPanel.txtFields[4].getText());
        attr[5] = Integer.parseInt(lvlPanel.txtFields[5].getText());
        //            validationMess.setText("");
        //            validationMess.setVisible(false);
        if (StringUtils.isNotBlank(image) && StringUtils.isNotBlank(health) && StringUtils.isNotBlank(attackPts)
                && StringUtils.isNotBlank(armourPts) && StringUtils.isNotBlank(attackRnge)
                && StringUtils.isNotBlank(movement) && StringUtils.isNotBlank(type)
                && StringUtils.isNotBlank(weapon)) {
            validationMess.setVisible(false);
            Player player = new Player();
            //have to remove the following statement later..
            player.setName(name);
            player.setAttackPts(Integer.parseInt(attackPts));
            player.setAttackRange(Integer.parseInt(attackRnge));
            player.setHealth(Integer.parseInt(health));
            player.setImagePath(image);
            player.setMovement(Integer.parseInt(movement));
            player.setArmor(Integer.parseInt(armourPts));
            player.setType(type);
            Inventory inventory = new Inventory();
            int position = GameUtils.getPositionOfWeaponItem(weapon);
            Weapon weaponObj = (Weapon) GameBean.weaponDetails.get(position);
            inventory.setEquippedWeapon(weaponObj);
            player.setInventory(inventory);
            player.setLevel(attr[0]);
            player.setExp(attr[1]);
            player.setStrength(attr[2]);
            player.setVitality(attr[3]);
            player.setDexterity(attr[4]);
            player.setWisdom(attr[5]);
            boolean characterAlrdyPresent = false;
            for (int i = 0; i < GameBean.playerDetails.size(); i++) {
                Player charFromList = (Player) GameBean.playerDetails.get(i);
                if (charFromList.getType().equalsIgnoreCase(type)) {
                    GameBean.playerDetails.remove(i);
                    characterAlrdyPresent = true;
                }
            }
            GameBean.playerDetails.add(player);
            try {
                GameUtils.writeCharactersToXML(GameBean.playerDetails, Configuration.PATH_FOR_USER_CHARACTERS);
                validationMess.setText("Saved Successfully..");
                validationMess.setVisible(true);
                if (!characterAlrdyPresent) {
                    comboBox.addItem(type);
                    comboBox.removeActionListener(this);
                    comboBox.setSelectedItem(type);
                    comboBox.addActionListener(this);
                }
            } catch (Exception e) {
                System.out.println("PlayerEditor : actionPerformed() : Some error occured " + e);
                validationMess.setText("Some error occured..");
                validationMess.setVisible(true);
                e.printStackTrace();
            }

        } else {
            validationMess.setText("Pls enter all the fields or pls choose a character from the drop down");
            validationMess.setVisible(true);
        }
    }
    this.revalidate();
    //        JFrame frame = (JFrame)SwingUtilities.getAncestorNamed("Frame", this);
    //        frame.revalidate();
}