Java JComboBox Event createComboBox(String actionCommand, ActionListener listener, String... items)

Here you can find the source of createComboBox(String actionCommand, ActionListener listener, String... items)

Description

create Combo Box

License

Creative Commons License

Declaration

@SuppressWarnings({ "rawtypes", "unchecked" })
    public static JComboBox createComboBox(String actionCommand, ActionListener listener, String... items) 

Method Source Code

//package com.java2s;
/*/*from ww w .j  a  v  a2 s .  c o  m*/
 * CS 106A
 *
 * This instructor-provided file contains utility functions related to GUIs.
 *
 * Author : Marty Stepp
 * Version: Tue 2014/06/05
 * 
 * This file and its contents are copyright (C) Stanford University and Marty Stepp,
 * licensed under Creative Commons Attribution 2.5 License.  All rights reserved.
 */

import java.awt.event.*;

import javax.swing.*;

public class Main {
    @SuppressWarnings({ "rawtypes", "unchecked" })
    public static JComboBox createComboBox(String actionCommand, ActionListener listener, String... items) {
        JComboBox box = new JComboBox();
        box.setEditable(false);
        for (String item : items) {
            box.addItem(item);
        }
        if (listener != null) {
            box.addActionListener(listener);
            box.setActionCommand(actionCommand);
        }
        return box;
    }
}

Related

  1. addActionListener(ActionListener listener, JComboBox... components)
  2. addActionListeners(JComboBox comboBox, ActionListener[] listeners)
  3. createComboBox(TYPE[] items, ActionListener... listeners)
  4. installComboBoxCopyAction(JComboBox comboBox)
  5. setAction(JComboBox cmb, ActionListener listener, String actionCommand)