Example usage for javax.swing JComboBox addItem

List of usage examples for javax.swing JComboBox addItem

Introduction

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

Prototype

public void addItem(E item) 

Source Link

Document

Adds an item to the item list.

Usage

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 v a 2  s  .  com
    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 w w w  .  j  a v a2 s  .  com*/
    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();/*from   w  ww.  j  a  v  a 2 s  .  c  o  m*/
    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:storybook.model.EntityUtil.java

@SuppressWarnings("unchecked")
public static void fillAutoCombo(MainFrame mainFrame, AutoCompleteComboBox autoCombo,
        AbstractEntityHandler entityHandler, String text, String methodName) {
    try {//from  w ww.  j av a2  s .com
        JComboBox combo = autoCombo.getJComboBox();
        combo.removeAllItems();
        BookModel model = mainFrame.getBookModel();
        Session session = model.beginTransaction();
        SbGenericDAOImpl<?, ?> dao = entityHandler.createDAO();
        dao.setSession(session);
        Method m = dao.getClass().getMethod(methodName, (Class<?>[]) null);
        List<Object> items = (List<Object>) m.invoke(dao);
        model.commit();
        for (Object item : items) {
            if (item == null || ((item instanceof String) && (((String) item).isEmpty()))) {
                continue;
            }
            combo.addItem(item);
        }
        combo.addItem("");
        combo.getModel().setSelectedItem(text);
        combo.revalidate();
    } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
            | InvocationTargetException e) {
        SbApp.error("EntityUtil.copyEntityProperties()", e);
    }
}

From source file:storybook.model.EntityUtil.java

@SuppressWarnings("unchecked")
public static void fillEntityCombo(MainFrame mainFrame, JComboBox combo, AbstractEntityHandler entityHandler,
        AbstractEntity entity, boolean isNew, boolean addEmptyItem) {
    combo.removeAllItems();/* w  w  w. j  a v a  2s . c  om*/
    ListCellRenderer renderer = entityHandler.getListCellRenderer();
    if (renderer != null) {
        combo.setRenderer(renderer);
    }
    int i = 0;
    if (addEmptyItem) {
        ++i;
        combo.addItem("");
    }
    BookModel model = mainFrame.getBookModel();
    Session session = model.beginTransaction();
    SbGenericDAOImpl<?, ?> dao = entityHandler.createDAO();
    dao.setSession(session);
    @SuppressWarnings("unchecked")
    List<AbstractEntity> entities = (List<AbstractEntity>) dao.findAll();
    for (AbstractEntity entity2 : entities) {
        session.refresh(entity2);
        combo.addItem(entity2);
        if (entity != null) {
            if (entity.getId().equals(entity2.getId())) // don't use combo.setSelectedItem(entity) here
            // leads to a "no session" exception for tag links
            {
                combo.setSelectedIndex(i);
            }
        }
        ++i;
    }
    combo.revalidate();
    model.commit();
}

From source file:test.visualization.PluggableRendererDemo.java

/**
 * @param jp    panel to which controls will be added
 *///from  w  w  w . j a  va2  s. c o m
@SuppressWarnings("serial")
protected void addBottomControls(final JPanel jp) {
    final JPanel control_panel = new JPanel();
    jp.add(control_panel, BorderLayout.EAST);
    control_panel.setLayout(new BorderLayout());
    final Box vertex_panel = Box.createVerticalBox();
    vertex_panel.setBorder(BorderFactory.createTitledBorder("Vertices"));
    final Box edge_panel = Box.createVerticalBox();
    edge_panel.setBorder(BorderFactory.createTitledBorder("Edges"));
    final Box both_panel = Box.createVerticalBox();

    control_panel.add(vertex_panel, BorderLayout.NORTH);
    control_panel.add(edge_panel, BorderLayout.SOUTH);
    control_panel.add(both_panel, BorderLayout.CENTER);

    // set up vertex controls
    v_color = new JCheckBox("seed highlight");
    v_color.addActionListener(this);
    v_stroke = new JCheckBox("stroke highlight on selection");
    v_stroke.addActionListener(this);
    v_labels = new JCheckBox("show voltage values");
    v_labels.addActionListener(this);
    v_shape = new JCheckBox("shape by degree");
    v_shape.addActionListener(this);
    v_size = new JCheckBox("size by voltage");
    v_size.addActionListener(this);
    v_size.setSelected(true);
    v_aspect = new JCheckBox("stretch by degree ratio");
    v_aspect.addActionListener(this);
    v_small = new JCheckBox("filter when degree < " + VertexDisplayPredicate.MIN_DEGREE);
    v_small.addActionListener(this);

    vertex_panel.add(v_color);
    vertex_panel.add(v_stroke);
    vertex_panel.add(v_labels);
    vertex_panel.add(v_shape);
    vertex_panel.add(v_size);
    vertex_panel.add(v_aspect);
    vertex_panel.add(v_small);

    // set up edge controls
    JPanel gradient_panel = new JPanel(new GridLayout(1, 0));
    gradient_panel.setBorder(BorderFactory.createTitledBorder("Edge paint"));
    no_gradient = new JRadioButton("Solid color");
    no_gradient.addActionListener(this);
    no_gradient.setSelected(true);
    //      gradient_absolute = new JRadioButton("Absolute gradient");
    //      gradient_absolute.addActionListener(this);
    gradient_relative = new JRadioButton("Gradient");
    gradient_relative.addActionListener(this);
    ButtonGroup bg_grad = new ButtonGroup();
    bg_grad.add(no_gradient);
    bg_grad.add(gradient_relative);
    //bg_grad.add(gradient_absolute);
    gradient_panel.add(no_gradient);
    //gradientGrid.add(gradient_absolute);
    gradient_panel.add(gradient_relative);

    JPanel shape_panel = new JPanel(new GridLayout(3, 2));
    shape_panel.setBorder(BorderFactory.createTitledBorder("Edge shape"));
    e_line = new JRadioButton("line");
    e_line.addActionListener(this);
    e_line.setSelected(true);
    //        e_bent = new JRadioButton("bent line");
    //        e_bent.addActionListener(this);
    e_wedge = new JRadioButton("wedge");
    e_wedge.addActionListener(this);
    e_quad = new JRadioButton("quad curve");
    e_quad.addActionListener(this);
    e_cubic = new JRadioButton("cubic curve");
    e_cubic.addActionListener(this);
    e_ortho = new JRadioButton("orthogonal");
    e_ortho.addActionListener(this);
    ButtonGroup bg_shape = new ButtonGroup();
    bg_shape.add(e_line);
    //        bg.add(e_bent);
    bg_shape.add(e_wedge);
    bg_shape.add(e_quad);
    bg_shape.add(e_ortho);
    bg_shape.add(e_cubic);
    shape_panel.add(e_line);
    //        shape_panel.add(e_bent);
    shape_panel.add(e_wedge);
    shape_panel.add(e_quad);
    shape_panel.add(e_cubic);
    shape_panel.add(e_ortho);
    fill_edges = new JCheckBox("fill edge shapes");
    fill_edges.setSelected(false);
    fill_edges.addActionListener(this);
    shape_panel.add(fill_edges);
    shape_panel.setOpaque(true);
    e_color = new JCheckBox("highlight edge weights");
    e_color.addActionListener(this);
    e_labels = new JCheckBox("show edge weight values");
    e_labels.addActionListener(this);
    e_uarrow_pred = new JCheckBox("undirected");
    e_uarrow_pred.addActionListener(this);
    e_darrow_pred = new JCheckBox("directed");
    e_darrow_pred.addActionListener(this);
    e_darrow_pred.setSelected(true);
    JPanel arrow_panel = new JPanel(new GridLayout(1, 0));
    arrow_panel.setBorder(BorderFactory.createTitledBorder("Show arrows"));
    arrow_panel.add(e_uarrow_pred);
    arrow_panel.add(e_darrow_pred);

    e_show_d = new JCheckBox("directed");
    e_show_d.addActionListener(this);
    e_show_d.setSelected(true);
    e_show_u = new JCheckBox("undirected");
    e_show_u.addActionListener(this);
    e_show_u.setSelected(true);
    JPanel show_edge_panel = new JPanel(new GridLayout(1, 0));
    show_edge_panel.setBorder(BorderFactory.createTitledBorder("Show edges"));
    show_edge_panel.add(e_show_u);
    show_edge_panel.add(e_show_d);

    shape_panel.setAlignmentX(Component.LEFT_ALIGNMENT);
    edge_panel.add(shape_panel);
    gradient_panel.setAlignmentX(Component.LEFT_ALIGNMENT);
    edge_panel.add(gradient_panel);
    show_edge_panel.setAlignmentX(Component.LEFT_ALIGNMENT);
    edge_panel.add(show_edge_panel);
    arrow_panel.setAlignmentX(Component.LEFT_ALIGNMENT);
    edge_panel.add(arrow_panel);

    e_color.setAlignmentX(Component.LEFT_ALIGNMENT);
    edge_panel.add(e_color);
    e_labels.setAlignmentX(Component.LEFT_ALIGNMENT);
    edge_panel.add(e_labels);

    // set up zoom controls
    zoom_at_mouse = new JCheckBox("<html><center>zoom at mouse<p>(wheel only)</center></html>");
    zoom_at_mouse.addActionListener(this);
    zoom_at_mouse.setSelected(true);

    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());
        }
    });

    JPanel zoomPanel = new JPanel();
    zoomPanel.setBorder(BorderFactory.createTitledBorder("Zoom"));
    plus.setAlignmentX(Component.CENTER_ALIGNMENT);
    zoomPanel.add(plus);
    minus.setAlignmentX(Component.CENTER_ALIGNMENT);
    zoomPanel.add(minus);
    zoom_at_mouse.setAlignmentX(Component.CENTER_ALIGNMENT);
    zoomPanel.add(zoom_at_mouse);

    JPanel fontPanel = new JPanel();
    // add font and zoom controls to center panel
    font = new JCheckBox("bold text");
    font.addActionListener(this);
    font.setAlignmentX(Component.CENTER_ALIGNMENT);
    fontPanel.add(font);

    both_panel.add(zoomPanel);
    both_panel.add(fontPanel);

    JComboBox modeBox = gm.getModeComboBox();
    modeBox.setAlignmentX(Component.CENTER_ALIGNMENT);
    JPanel modePanel = new JPanel(new BorderLayout()) {
        public Dimension getMaximumSize() {
            return getPreferredSize();
        }
    };
    modePanel.setBorder(BorderFactory.createTitledBorder("Mouse Mode"));
    modePanel.add(modeBox);
    JPanel comboGrid = new JPanel(new GridLayout(0, 1));
    comboGrid.add(modePanel);
    fontPanel.add(comboGrid);

    JComboBox cb = new JComboBox();
    cb.addItem(Renderer.VertexLabel.Position.N);
    cb.addItem(Renderer.VertexLabel.Position.NE);
    cb.addItem(Renderer.VertexLabel.Position.E);
    cb.addItem(Renderer.VertexLabel.Position.SE);
    cb.addItem(Renderer.VertexLabel.Position.S);
    cb.addItem(Renderer.VertexLabel.Position.SW);
    cb.addItem(Renderer.VertexLabel.Position.W);
    cb.addItem(Renderer.VertexLabel.Position.NW);
    cb.addItem(Renderer.VertexLabel.Position.N);
    cb.addItem(Renderer.VertexLabel.Position.CNTR);
    cb.addItem(Renderer.VertexLabel.Position.AUTO);
    cb.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            Renderer.VertexLabel.Position position = (Renderer.VertexLabel.Position) e.getItem();
            vv.getRenderer().getVertexLabelRenderer().setPosition(position);
            vv.repaint();
        }
    });
    cb.setSelectedItem(Renderer.VertexLabel.Position.SE);
    JPanel positionPanel = new JPanel();
    positionPanel.setBorder(BorderFactory.createTitledBorder("Label Position"));
    positionPanel.add(cb);

    comboGrid.add(positionPanel);

}

From source file:uk.chromis.pos.imports.JPanelCSVImport.java

private void jComboBoxFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jComboBoxFocusGained
    JComboBox myJComboBox = ((javax.swing.JComboBox) (evt.getComponent()));
    myJComboBox.removeAllItems();/*from w w w .j a v  a 2  s. c  o m*/
    int i = 1;
    myJComboBox.addItem("");
    while (i < Headers.size()) {
        if (!isEntryInUse(Headers.get(i))) {
            myJComboBox.addItem(Headers.get(i));
        }
        ++i;
    }
    jComboCategory.addItem(category_disable_text);
}