Example usage for javax.swing JComboBox getSelectedIndex

List of usage examples for javax.swing JComboBox getSelectedIndex

Introduction

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

Prototype

@Transient
public int getSelectedIndex() 

Source Link

Document

Returns the first item in the list that matches the given item.

Usage

From source file:se.llbit.chunky.renderer.ui.RenderControls.java

private JPanel buildPostProcessingPane() {
    exposure.update();//from   w  ww .  j a va 2 s.c  o m

    JLabel postprocessDescLbl = new JLabel(
            "<html>Post processing affects rendering performance<br>when the preview window is visible");
    JLabel postprocessLbl = new JLabel("Post-processing mode:");
    for (Postprocess pp : Postprocess.values) {
        postprocessCB.addItem("" + pp);
    }
    updatePostprocessCB();
    postprocessCB.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JComboBox source = (JComboBox) e.getSource();
            renderMan.scene().setPostprocess(Postprocess.get(source.getSelectedIndex()));
        }
    });

    JPanel panel = new JPanel();
    GroupLayout layout = new GroupLayout(panel);
    panel.setLayout(layout);
    layout.setHorizontalGroup(layout.createSequentialGroup().addContainerGap()
            .addGroup(layout.createParallelGroup().addGroup(exposure.horizontalGroup(layout))
                    .addGroup(layout.createSequentialGroup().addComponent(postprocessLbl)
                            .addPreferredGap(ComponentPlacement.RELATED).addComponent(postprocessCB))
                    .addComponent(postprocessDescLbl))
            .addContainerGap());
    layout.setVerticalGroup(
            layout.createSequentialGroup().addContainerGap().addGroup(exposure.verticalGroup(layout))
                    .addPreferredGap(ComponentPlacement.UNRELATED).addPreferredGap(ComponentPlacement.UNRELATED)
                    .addGroup(layout.createParallelGroup(Alignment.BASELINE).addComponent(postprocessLbl)
                            .addComponent(postprocessCB))
                    .addPreferredGap(ComponentPlacement.RELATED).addComponent(postprocessDescLbl)
                    .addContainerGap());
    return panel;
}

From source file:shuffle.fwk.service.roster.EditRosterService.java

private JPanel createRosterComponent(Species s) {
    JPanel ret = new JPanel(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.BOTH;
    c.gridx = 1;/*from  w  w w.  j a  va 2  s  . c o m*/
    c.gridy = 1;
    c.anchor = GridBagConstraints.CENTER;

    MouseAdapter ma = new PressOrClickMouseAdapter() {

        @Override
        protected void onRight(MouseEvent e) {
            onLeft(e);
        }

        @Override
        protected void onLeft(MouseEvent e) {
            setSelected(s, ret);
            selectedDisplayLabel.repaint();
        }

        @Override
        protected void onEnter() {
            // Do nothing
        }
    };
    SpeciesPaint sp = new SpeciesPaint(s, false, getMegaFilter());
    ImageIcon icon = getUser().getImageManager().getImageFor(sp);
    JLabel iconLabel = new JLabel(icon);
    iconLabel.addMouseListener(ma);
    ret.add(iconLabel, c);
    c.gridy += 1;
    JLabel jLabel = new JLabel(s.getLocalizedName(getMegaFilter()));
    jLabel.setHorizontalTextPosition(SwingConstants.CENTER);
    jLabel.setHorizontalAlignment(SwingConstants.CENTER);
    jLabel.addMouseListener(ma);
    ret.add(jLabel, c);
    JComboBox<Integer> level = new JComboBox<Integer>();
    for (int i = 0; i <= Species.MAX_LEVEL; i++) {
        level.addItem(i);
    }
    Integer thisLevel = getLevelFor(s);
    level.setSelectedItem(thisLevel);
    level.setToolTipText(getString(KEY_POKEMON_LEVEL_TOOLTIP));
    c.gridy += 1; // put the level selector below the icon.
    ret.add(level, c);
    level.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            int index = level.getSelectedIndex();
            myData.setLevelForSpecies(s, index);
            rebuildSelectedLabel();
        }
    });
    return ret;
}

From source file:shuffle.fwk.service.teams.EditTeamService.java

private Component createTeamComponent(Species s) {
    Team curTeam = getCurrentTeam();/*from ww  w .j  a v  a 2s  .c o  m*/
    JPanel ret = new JPanel(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.gridx = 1;
    c.gridy = 1;
    c.gridwidth = 2;
    Indicator<SpeciesPaint> ind = new Indicator<SpeciesPaint>(this);
    boolean isMega = megaProgress >= megaThreshold && s.getName().equals(curTeam.getMegaSlotName());
    SpeciesPaint paint = new SpeciesPaint(s, s.equals(Species.FREEZE), isMega);
    ind.setVisualized(paint);
    ret.add(ind, c);
    c.gridy += 1;
    c.gridwidth = 1;
    JButton removeButton = new JButton(getString(KEY_REMOVE));
    removeButton.setToolTipText(getString(KEY_REMOVE_TOOLTIP));
    removeButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            removeSpeciesFromTeam(s.getName());
            updateTeamPanel();
        }
    });
    removeButton.setEnabled(
            s.getEffect(getUser().getRosterManager()).isPickable() && !s.getType().equals(PkmType.NONE));
    ret.add(removeButton, c);

    c.gridx += 1;
    JComboBox<Character> keybindsComboBox = new JComboBox<Character>();
    Character curBinding = curTeam.getBinding(s);
    LinkedHashSet<Character> allBindingsFor = new LinkedHashSet<Character>(Arrays.asList(curBinding));
    LinkedHashSet<Character> availableBindings = myData.getAllAvailableBindingsFor(s.getName(), curTeam);
    allBindingsFor.addAll(availableBindings);
    for (Character ch : allBindingsFor) {
        keybindsComboBox.addItem(ch);
    }
    keybindsComboBox.setSelectedItem(curBinding);
    final ItemListener bindingListener = new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            JComboBox<?> source = (JComboBox<?>) e.getSource();
            int selectedIndex = source.getSelectedIndex();
            Character selected = (Character) source.getItemAt(selectedIndex);
            setBinding(s, selected);
            updateKeybindComboBoxes();
        }
    };
    nameToKeybindComboboxMap.put(s.getName(), keybindsComboBox);
    nameToItemListenerMap.put(s.getName(), bindingListener);
    keybindsComboBox.addItemListener(bindingListener);
    keybindsComboBox.setToolTipText(getString(KEY_KEYBINDS_TOOLTIP));
    ret.add(keybindsComboBox, c);

    MouseAdapter ma = new PressToggleMouseAdapter() {

        @Override
        protected void onRight(MouseEvent e) {
            doToggle();
        }

        @Override
        protected void onLeft(MouseEvent e) {
            doToggle();
        }

        private void doToggle() {
            toggleSupport(s);
            updateTeamPanel();
        }
    };
    ret.addMouseListener(ma);

    setBorderFor(ret, false, false);
    if (!Species.FIXED_SPECIES.contains(s)) {
        boolean isSupport = !curTeam.isNonSupport(s);
        Color indColor = isSupport ? Color.GREEN : Color.RED;
        ret.setBackground(indColor);
        ret.setOpaque(true);
    }
    return ret;
}

From source file:shuffle.fwk.service.teams.EditTeamService.java

private void updateKeybindComboBoxes() {
    Team curTeam = getCurrentTeam();//w  w  w  . j  a va 2s.c om
    for (String name : curTeam.getNames()) {
        ItemListener itemListener = nameToItemListenerMap.get(name);
        JComboBox<Character> box = nameToKeybindComboboxMap.get(name);
        box.removeItemListener(itemListener);
        Character prevSelected = box.getItemAt(box.getSelectedIndex());
        box.removeAllItems();
        Character curBinding = curTeam.getBinding(name);
        LinkedHashSet<Character> availableBindings = new LinkedHashSet<Character>(Arrays.asList(curBinding));
        availableBindings.addAll(myData.getAllAvailableBindingsFor(name, curTeam));
        for (Character ch : availableBindings) {
            if (ch != null) {
                box.addItem(ch);
            }
        }
        box.setSelectedItem(prevSelected);
        if (box.getSelectedIndex() < 0) {
            LOG.warning(getString(KEY_NO_BINDINGS));
        }
        box.addItemListener(itemListener);
    }
}

From source file:us.daveread.basicquery.BasicQuery.java

/**
 * Checks whether an input (query or connect string) is already in its
 * associated combo box. If not, the new information is added to the combo
 * list/*from ww  w.  j  a  v a  2  s .  c o  m*/
 * 
 * @param combo
 *          JComboBox which has a list of the query statements or connect
 *          strings.
 */
private void checkForNewString(JComboBox combo) {
    // String newString, foundString;
    Object newValue;
    int checkDups, matchAt;
    boolean match;
    // boolean newCommented, foundCommented;

    // newCommented = foundCommented = false;
    matchAt = -1;

    if (combo == querySelection) {
        newValue = new Query(queryText.getText(), whichModeValue());
        // newString = queryText.getText();
        // newString = newString.replace('\n', ' ');
    } else {
        // newString = (String)combo.getEditor().getItem();
        newValue = combo.getEditor().getItem();
    }

    // if (newString.startsWith(COMMENT_PREFIX)) {
    // newCommented = true;
    // newString = newString.substring(2);
    // }

    // if (newString.trim().length() > 0) {
    if (newValue.toString().length() > 0) {
        match = false;
        for (checkDups = 0; checkDups < combo.getItemCount() && !match; ++checkDups) {
            // if (combo == querySelection) {
            // foundString = ((Query)combo.getItemAt(checkDups)).getSQL();
            // } else {
            // foundString = ((String)combo.getItemAt(checkDups));
            // }

            // if (foundString.startsWith(COMMENT_PREFIX)) {
            // foundString = foundString.substring(2);
            // foundCommented = true;
            // } else {
            // foundCommented = false;
            // }

            // if (newString.equals(foundString)) {
            if (newValue.equals(combo.getItemAt(checkDups))) {
                match = true;
                if (combo == querySelection) {
                    ((Query) combo.getItemAt(checkDups)).setMode(whichModeValue());
                }
                combo.setSelectedIndex(checkDups);
                matchAt = checkDups;
            }
        }

        // if (newCommented) {
        // newString = COMMENT_PREFIX + newString;
        // }

        if (!match) {
            addToCombo(combo, newValue);
            if (combo == querySelection) {
                // addToCombo(combo, new Query(newString, whichModeValue()));
                combo.setSelectedIndex(combo.getModel().getSize() - 1);
                matchAt = combo.getSelectedIndex();
            }
        }
        // if (foundCommented != newCommented) {
        // if (combo == querySelection) {
        // replaceInCombo(combo, matchAt,
        // new Query(newString, whichModeValue()));
        // } else {
        // replaceInCombo(combo, matchAt, newString);
        // }
        // }
        if (combo == querySelection) {
            if (((Query) newValue).isCommented() != ((Query) combo.getSelectedItem()).isCommented()) {
                replaceInCombo(combo, matchAt, newValue);
            }
        }
    }
}

From source file:Widgets.Simulation.java

protected JPanel trajectoryTabb() {
    JPanel trajectoryPanel = new JPanel();

    //judge if converged
    //final JLabel convergePanel = new JLabel();   
    plot.removeAllPlots();/* w w  w  . ja  v a2 s. c o  m*/

    plot.setAxisLabel(0, "t");
    plot.setAxisLabel(1, "Expression Level");
    plot.setPreferredSize(new Dimension(440, 390));

    //ArrayList<DoubleMatrix2D> timeSeries_ = grn.getTimeSeries();
    //ArrayList<DoubleMatrix1D> timeScale_ = grn.getTimeScale();

    //display multiple time series
    //combobox
    //generate time series List
    String[] timeSeriesList = new String[grn.getTimeSeries().size()];

    for (int i = 0; i < grn.getTimeSeries().size(); i++)
        timeSeriesList[i] = Integer.toString(i);

    JLabel selectPanelName = new JLabel("Select trajectory: ");
    JPanel selectPanel = new JPanel();
    //selectPanel.setPreferredSize(new Dimension(1000,10));
    final JComboBox<String> combo = new JComboBox<String>(timeSeriesList);

    //view window
    final JPanel trajectoryViewPanel = new JPanel();
    //trajectoryViewPanel.setPreferredSize(new Dimension(990,500));

    plot.setPreferredSize(new Dimension(440, 350));
    double[] t = grn.getTimeScale().get(0).toArray();
    for (int k = 0; k < grn.getTimeSeries().get(0).columns(); k++)
        plot.addLinePlot(grn.getNode(k).getLabel(), t, grn.getTimeSeries().get(0).viewColumn(k).toArray());
    plot.addLegend("SOUTH");
    plot.repaint();

    //combobox action             
    combo.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            int row = combo.getSelectedIndex();

            plot.removeAllPlots();

            double[] t = grn.getTimeScale().get(row).toArray();
            for (int k = 0; k < grn.getTimeSeries().get(row).columns(); k++) {
                plot.addLinePlot(grn.getNode(k).getLabel(), t,
                        grn.getTimeSeries().get(row).viewColumn(k).toArray());
            }

            trajectoryViewPanel.repaint();
            trajectoryViewPanel.setVisible(true);
        }
    });

    selectPanel.setLayout(new BoxLayout(selectPanel, BoxLayout.X_AXIS));
    selectPanel.add(selectPanelName);
    selectPanel.add(combo);
    trajectoryViewPanel.add(plot);

    //set layout
    trajectoryPanel.setLayout(new GridBagLayout());
    NetLand.addComponent(trajectoryPanel, trajectoryViewPanel, 0, 0, 1, 1, GridBagConstraints.NORTHWEST,
            GridBagConstraints.BOTH, 0, 1);
    NetLand.addComponent(trajectoryPanel, selectPanel, 0, 1, 1, 1, GridBagConstraints.NORTHWEST,
            GridBagConstraints.BOTH, 1, 0);
    //NetLand.addComponent(trajectoryPanel, convergePanel, 0, 2, 1, 1, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, 1, 0);

    return trajectoryPanel;
}