Example usage for javax.swing JComboBox setActionCommand

List of usage examples for javax.swing JComboBox setActionCommand

Introduction

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

Prototype

public void setActionCommand(String aCommand) 

Source Link

Document

Sets the action command that should be included in the event sent to action listeners.

Usage

From source file:SaveImage.java

public static void main(String s[]) {
    JFrame f = new JFrame("Save Image Sample");
    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);// w  w w .j  a  v a2s  . co m
        }
    });
    SaveImage si = new SaveImage();
    f.add("Center", si);
    JComboBox choices = new JComboBox(si.getDescriptions());
    choices.setActionCommand("SetFilter");
    choices.addActionListener(si);
    JComboBox formats = new JComboBox(si.getFormats());
    formats.setActionCommand("Formats");
    formats.addActionListener(si);
    JPanel panel = new JPanel();
    panel.add(choices);
    panel.add(new JLabel("Save As"));
    panel.add(formats);
    f.add("South", panel);
    f.pack();
    f.setVisible(true);
}

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 av  a  2  s  .com
    jc.setActionCommand("Action");
    String cmd = jc.getActionCommand();

}

From source file:fuel.gui.stats.MotorStatsPanel.java

public MotorStatsPanel(Database database) throws SQLException {
    this.database = database;
    controller = new Controller();
    JPanel container = new JPanel(new BorderLayout());
    //container.setLayout(new BoxLayout(container, BoxLayout.Y_AXIS));
    JPanel motorSelectionPanel = new JPanel();
    motorSelectionPanel.setLayout(new BoxLayout(motorSelectionPanel, BoxLayout.X_AXIS));
    motorSpecsPanel = new JPanel(new GridLayout(2, 3));
    motorSpecsPanel.setBorder(BorderFactory.createTitledBorder("Specs"));
    graphContainer = new JPanel();
    graphContainer.setLayout(new BoxLayout(graphContainer, BoxLayout.Y_AXIS));
    JComboBox motorSelector = new JComboBox(database.getMotorcycles().toArray());
    motorSelector.setActionCommand("SELECTMOTOR");
    motorSelector.addActionListener(controller);
    motorSelectionPanel.add(motorSelector);

    //motorSelector.setSelectedIndex(0);

    motorSelectionPanel.add(motorSpecsPanel);
    refreshMotorSpecs((Motorcycle) motorSelector.getSelectedItem());

    container.add(motorSelectionPanel, BorderLayout.NORTH);
    JScrollPane scroll = new JScrollPane(graphContainer);
    scroll.getHorizontalScrollBar().setUnitIncrement(10);
    scroll.getVerticalScrollBar().setUnitIncrement(10);
    container.add(scroll, BorderLayout.CENTER);

    refreshGraphs((Motorcycle) motorSelector.getSelectedItem());
    setLayout(new BorderLayout());
    add(container);/*from  w w  w .  j  ava  2s  .co  m*/

    setVisible(true);
}

From source file:MainClass.java

public MainClass() {
    // Build a mapping from book titles to their entries
    for (int i = 0; i < items.length; i++) {
        itemMap.put(items[i].getTitle(), items[i]);
    }/*from   w w  w.  j a v  a 2  s.c  o  m*/

    setLayout(new BorderLayout());

    JComboBox bookCombo = new JComboBox(items);
    bookCombo.setEditable(true);
    bookCombo.setEditor(new MyComboBoxEditor(itemMap, items[0]));
    bookCombo.setMaximumRowCount(4);
    bookCombo.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("You chose " + ((JComboBox) e.getSource()).getSelectedItem() + "!");
        }
    });
    bookCombo.setActionCommand("Hello");
    add(bookCombo, BorderLayout.CENTER);
}

From source file:Main.java

public Main() {
    // Build a mapping from book titles to their entries
    for (int i = 0; i < items.length; i++) {
        itemMap.put(items[i].getTitle(), items[i]);
    }/*from ww  w . jav a 2  s  . c  o  m*/

    setLayout(new BorderLayout());

    JComboBox bookCombo = new JComboBox(items);
    bookCombo.setEditable(true);
    bookCombo.setEditor(new MyComboBoxEditor(itemMap, items[0]));
    bookCombo.setMaximumRowCount(4);
    bookCombo.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("You chose " + ((JComboBox) e.getSource()).getSelectedItem() + "!");
        }
    });
    bookCombo.setActionCommand("Hello");
    add(bookCombo, BorderLayout.CENTER);
}

From source file:EditableComboBox.java

public EditableComboBox() {
    // Build a mapping from book titles to their entries
    for (int i = 0; i < books.length; i++) {
        bookMap.put(books[i].getTitle(), books[i]);
    }//from   ww w .j  av  a 2  s  .  co m

    setLayout(new BorderLayout());

    JComboBox bookCombo = new JComboBox(books);
    bookCombo.setEditable(true);
    bookCombo.setEditor(new ComboBoxEditorExample(bookMap, books[0]));
    bookCombo.setMaximumRowCount(4);
    bookCombo.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("You chose " + ((JComboBox) e.getSource()).getSelectedItem() + "!");
        }
    });
    bookCombo.setActionCommand("Hello");
    add(bookCombo, BorderLayout.CENTER);
}

From source file:imageuploader.ImgWindow.java

private void setExplicitSelectionManager(JComboBox comboBox) {

    class ExplicitSelectionManager implements KeyListener, FocusListener {

        private JComboBox src;
        private KeyListener superKeyListener;

        ExplicitSelectionManager(JComboBox src) {
            this.src = src;

            //   we like what the default key listener does, but not the action command
            // it uses for ActionEvents it fires for plain text type-ahead characters
            this.superKeyListener = src.getKeyListeners()[0]; // we only have one
            src.removeKeyListener(superKeyListener); // will be replace right away, below
        }//www .  j av  a2s .c  om

        @Override
        public void keyTyped(KeyEvent e) {
            // basic combo box has no code in keyTyped
        }

        @Override
        public void keyPressed(KeyEvent e) {

            //   in the default JComboBox implementation, the KeySelectionManager is
            // called from keyPressed. I'm fine with the implementation of
            // the default, but I don't want it firing ActionEvents that will cause
            // model updates
            src.setActionCommand("comboBoxMovement");
            this.superKeyListener.keyPressed(e);
            src.setActionCommand("comboBoxChanged");

            if (e.getKeyCode() == 10) {
                src.setSelectedIndex(src.getSelectedIndex());
            }
        }

        @Override
        public void keyReleased(KeyEvent e) {
            // basic combo box has no code in keyReleased
        }

        @Override
        public void focusGained(FocusEvent e) {
        }

        @Override
        //  this will also give us the event we want, if the user decides to Tab out of
        // the combo box, instead of hitting Enter
        public void focusLost(FocusEvent e) {
            src.setSelectedIndex(src.getSelectedIndex());
        }

    }

    ExplicitSelectionManager newSelectionManager = new ExplicitSelectionManager(comboBox);

    comboBox.addKeyListener(newSelectionManager);
    comboBox.addFocusListener(newSelectionManager);

}

From source file:ffx.ui.ModelingPanel.java

private void initCommandComboBox(JComboBox commands) {
    commands.setActionCommand("FFXCommand");
    commands.setMaximumSize(xyzCommands.getPreferredSize());
    commands.setEditable(false);/*from   w  ww.jav  a2 s. c  o  m*/
    commands.setToolTipText("Select a Modeling Command");
    commands.setSelectedIndex(0);
    commands.addActionListener(this);
}

From source file:org.openmicroscopy.shoola.agents.imviewer.util.player.MoviePlayerControl.java

/** Adds listeners to the UI components. */
private void initListeners() {
    JTextField editor = view.editor;
    editor.addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER)
                editorActionHandler();/*from   www . j av  a 2  s.  c o  m*/
        }
    });
    //JButton
    attachButtonListener(view.play, PLAY_CMD);
    attachButtonListener(view.pause, PAUSE_CMD);
    attachButtonListener(view.stop, STOP_CMD);
    //JComboBox
    JComboBox box = view.movieTypes;
    box.setActionCommand("" + MOVIE_TYPE_CMD);
    box.addActionListener(this);
    //JSpinner
    view.fps.addChangeListener(this);
    //MoviePane
    attachFieldListeners(view.startT);
    attachFieldListeners(view.endT);
    attachFieldListeners(view.startZ);
    attachFieldListeners(view.endZ);
    attachButtonListener(view.acrossZ, ACROSS_Z_CMD);
    attachButtonListener(view.acrossT, ACROSS_T_CMD);
    //attachButtonListener(view.acrossZT, ACROSS_ZT_CMD);
    view.tSlider.addPropertyChangeListener(this);
    view.zSlider.addPropertyChangeListener(this);
}