Example usage for javax.swing JComboBox getActionCommand

List of usage examples for javax.swing JComboBox getActionCommand

Introduction

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

Prototype

public String getActionCommand() 

Source Link

Document

Returns the action command that is included in the event sent to action listeners.

Usage

From source file:Main.java

public Main() {
    JComboBox jc = new JComboBox();
    jc.addItem("France");
    jc.addItem("Germany");
    jc.addItem("Italy");
    jc.addItem("Japan");
    jc.addItemListener(this);
    add(jc);//ww  w  . j ava2s.  c om
    String cmd = jc.getActionCommand();

}

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  .ja v a  2  s .  co  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:Main.java

public Main() {
    JComboBox jc = new JComboBox();
    jc.addItem("France");
    jc.addItem("Germany");
    jc.addItem("Italy");
    jc.addItem("Japan");
    jc.addItemListener(this);
    add(jc);//from  w  ww  .j  a  va2  s  .c o  m
    jc.setActionCommand("Action");
    String cmd = jc.getActionCommand();

}