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:Main.java

public void actionPerformed(ActionEvent e) {
    JComboBox jcb = (JComboBox) e.getSource();
    System.out.println("down action");
    ComboBoxUI ui = jcb.getUI();/*from   ww w .  ja  v  a2s.  c o m*/

    if (ui.isPopupVisible(jcb)) {
        int i = jcb.getSelectedIndex();
        if (i < jcb.getModel().getSize() - 1) {
            jcb.setSelectedIndex(i + 1);
            jcb.repaint();
        }
    } else {
        int nItems = jcb.getItemCount();

        ComboBoxEditor cbe = jcb.getEditor();

        String st; // Search text

        st = ((String) cbe.getItem()).toUpperCase();

        for (int i = 0; i < nItems; i++) {
            String item = ((String) jcb.getItemAt(i)).toUpperCase();

            if (item.startsWith(st)) {
                jcb.setSelectedIndex(i);
                break;
            }
        }

        ui.setPopupVisible(jcb, true);
    }
}

From source file:ImageDrawingComponent.java

public void buildUI() {
    final ImageDrawingComponent id = new ImageDrawingComponent(imageSrc);
    add("Center", id);
    JComboBox choices = new JComboBox(id.getDescriptions());
    choices.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JComboBox cb = (JComboBox) e.getSource();
            id.setOpIndex(cb.getSelectedIndex());
            id.repaint();//from w  w w  . j  a  va  2  s .  com
        };
    });
    add("South", choices);
}

From source file:ArcApp.java

public ArcApp() {
    super(new BorderLayout());
    canvas = new MyCanvas();
    int width = 600;
    int height = 55;
    sliderX = setSlider(0, width, width / 4, width / 2, width / 4);
    sliderY = setSlider(0, height, height / 4, height / 2, height / 4);
    sliderWidth = setSlider(0, width, width / 2, width / 2, width / 4);
    sliderHeight = setSlider(0, height, height / 2, height / 2, height / 4);
    sliderT0 = setSlider(0, 360, 45, 180, 45);
    sliderT = setSlider(0, 360, 135, 180, 45);

    JPanel panel1 = new JPanel();
    panel1.setLayout(new GridLayout(3, 3));
    panel1.add(new JLabel("Location (x,y): ", JLabel.RIGHT));
    panel1.add(sliderX);/*from w  ww  .  j  av a  2s.  c o m*/
    panel1.add(sliderY);
    panel1.add(new JLabel("Size (w,h): ", JLabel.RIGHT));
    panel1.add(sliderWidth);
    panel1.add(sliderHeight);
    panel1.add(new JLabel("Angles (Th0, Th): ", JLabel.RIGHT));
    panel1.add(sliderT0);
    panel1.add(sliderT);

    add(panel1, BorderLayout.NORTH);

    arcBox = new JComboBox(arcLabels);
    arcBox.setSelectedIndex(0);
    arcBox.setAlignmentX(Component.LEFT_ALIGNMENT);
    arcBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JComboBox cb = (JComboBox) e.getSource();
            canvas.arcType = arcTypes[cb.getSelectedIndex()];
            canvas.repaint();
        }
    });

    fillBox = new JComboBox(colorLabels);
    fillBox.setSelectedIndex(0);
    fillBox.setAlignmentX(Component.LEFT_ALIGNMENT);
    fillBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JComboBox cb = (JComboBox) e.getSource();
            canvas.fillColor = colors[cb.getSelectedIndex()];
            canvas.repaint();
        }
    });

    JPanel panel2 = new JPanel();
    panel2.setLayout(new GridLayout(1, 4));
    panel2.add(new JLabel("Arc Type: ", JLabel.RIGHT));
    panel2.add(arcBox);
    panel2.add(new JLabel("Fill Type: ", JLabel.RIGHT));
    panel2.add(fillBox);

    add(panel2, BorderLayout.SOUTH);
    add(canvas, BorderLayout.CENTER);
}

From source file:jmemorize.gui.swing.panels.HistoryChartPanel.java

private JPanel buildChartChooser() {
    JComboBox comboBox = new JComboBox(new String[] { Localization.get(LC.HISTORY_RECENT),
            Localization.get(LC.HISTORY_BY_DATE), Localization.get(LC.HISTORY_BY_WEEK),
            Localization.get(LC.HISTORY_BY_MONTH), Localization.get(LC.HISTORY_BY_YEAR), });

    comboBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JComboBox box = (JComboBox) e.getSource();
            m_mode = box.getSelectedIndex();
            updateDataSet();//from  w w w.ja  v a 2 s. c o m
        }
    });

    JPanel panel = new JPanel(new BorderLayout());
    panel.add(comboBox, BorderLayout.WEST);

    return panel;
}

From source file:SaveImage.java

public void actionPerformed(ActionEvent e) {
    JComboBox cb = (JComboBox) e.getSource();
    if (cb.getActionCommand().equals("SetFilter")) {
        setOpIndex(cb.getSelectedIndex());
        repaint();//from   w  w w.j a  v a 2  s .  c  o m
    } else if (cb.getActionCommand().equals("Formats")) {
        /*
         * Save the filtered image in the selected format. The selected item will
         * be the name of the format to use
         */
        String format = (String) cb.getSelectedItem();
        /*
         * Use the format name to initialise the file suffix. Format names
         * typically correspond to suffixes
         */
        File saveFile = new File("savedimage." + format);
        JFileChooser chooser = new JFileChooser();
        chooser.setSelectedFile(saveFile);
        int rval = chooser.showSaveDialog(cb);
        if (rval == JFileChooser.APPROVE_OPTION) {
            saveFile = chooser.getSelectedFile();
            /*
             * Write the filtered image in the selected format, to the file chosen
             * by the user.
             */
            try {
                ImageIO.write(biFiltered, format, saveFile);
            } catch (IOException ex) {
            }
        }
    }
}

From source file:carfuzzy.Operations.java

public double getMembership(JComboBox s, int input) {
    double membership;
    if (s.getSelectedIndex() == 0) { //veryslow ya da veryclose ise(left Trapezoid)
        if (s.getSelectedItem().getClass() == Speed.class) {
            speed = (Speed) s.getSelectedItem();
            membership = leftTrapezoidalMembership(input, speed.getValue());
            return membership;
        } else {/* ww  w  .j  a va 2s.c om*/
            distance = (Distance) s.getSelectedItem();
            membership = leftTrapezoidalMembership(input, distance.getValue());
            return membership;

        }
    } else if (s.getSelectedIndex() == s.getItemCount() - 1) { //veryfast ya da away ise(right Trapezoid)
        if (s.getSelectedItem().getClass() == Speed.class) {
            speed = (Speed) s.getSelectedItem();
            membership = rightTrapezoidalMembership(input, speed.getValue());
            return membership;
        } else {
            distance = (Distance) s.getSelectedItem();
            membership = rightTrapezoidalMembership(input, distance.getValue());
            return membership;
        }

    } else { // Triangular ise
        if (s.getSelectedItem().getClass() == Speed.class) {
            speed = (Speed) s.getSelectedItem();
            membership = triangularMembership(input, speed.getValue());
            return membership;
        } else {
            distance = (Distance) s.getSelectedItem();
            membership = triangularMembership(input, distance.getValue());
            return membership;
        }
    }
}

From source file:de.unibayreuth.bayeos.goat.options.JOptionDialog.java

private void jcbTypeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbTypeActionPerformed
    // Add your handling code here:
    JComboBox s = (JComboBox) evt.getSource();
    pref.putInt("xyitemrenderer", s.getSelectedIndex() + 1);
}

From source file:com.biosis.biosislite.vistas.Configuracion.java

private void guardar(Properties fichero, String urlFichero, JComboBox combo, JTextField txtConexion,
        JTextField txtUsuario, JTextField txtPassword) {

    int tipoBD = combo.getSelectedIndex() + 1;

    //        String driver = ParametrosUtil.obtenerDriver(tipoBD);
    String url = txtConexion.getText();
    String usuario = txtUsuario.getText();
    String password = txtPassword.getText();

    //        combo.setSelectedIndex(tipoBD - 1);
    txtConexion.setText(url);//  ww  w  .ja v a2 s .c o m
    txtUsuario.setText(usuario);
    txtPassword.setText(password);

    fichero.setProperty("url", url);
    fichero.setProperty("usuario", usuario);
    fichero.setProperty("password", Encriptador.encrypt(password));
    fichero.setProperty("tipo", tipoBD + "");

    PropertiesUtil.guardarProperties(fichero, urlFichero);
}

From source file:ComboBoxDemo.java

public ComboBoxDemo() {
    super(new BorderLayout());

    String[] petStrings = { "Bird", "Cat", "Dog", "Rabbit", "Pig" };

    //Create the combo box, select the item at index 4.
    //Indices start at 0, so 4 specifies the pig.
    JComboBox petList = new JComboBox(petStrings);
    petList.setSelectedIndex(4);/*from   ww w  .  ja va  2s.co  m*/
    petList.addActionListener(this);

    //Set up the picture.
    picture = new JLabel();
    picture.setFont(picture.getFont().deriveFont(Font.ITALIC));
    picture.setHorizontalAlignment(JLabel.CENTER);
    updateLabel(petStrings[petList.getSelectedIndex()]);
    picture.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0));

    //The preferred size is hard-coded to be the width of the
    //widest image and the height of the tallest image + the border.
    //A real program would compute this.
    picture.setPreferredSize(new Dimension(177, 122 + 10));

    //Lay out the demo.
    add(petList, BorderLayout.PAGE_START);
    add(picture, BorderLayout.PAGE_END);
    setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
}

From source file:edu.gmu.cs.sim.util.media.chart.HistogramGenerator.java

public HistogramGenerator() {
    // buildChart is called by super() first

    LabelledList list = new LabelledList("Show Histogram...");
    DisclosurePanel pan1 = new DisclosurePanel("Show Histogram...", list);

    final HistogramType[] styles = new HistogramType[] { HistogramType.FREQUENCY,
            HistogramType.RELATIVE_FREQUENCY, HistogramType.SCALE_AREA_TO_1 };
    final JComboBox style = new JComboBox(
            new String[] { "By Frequency", "By Relative Frequency", "With Area = 1.0" });
    style.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            histogramType = styles[style.getSelectedIndex()];
            HistogramDataset dataset = (HistogramDataset) (getSeriesDataset());
            dataset.setType(histogramType);
        }/*from  w w w.  ja  v a  2 s  . c o  m*/
    });
    list.add(style);
    addGlobalAttribute(pan1);
}