Example usage for javax.swing DefaultComboBoxModel DefaultComboBoxModel

List of usage examples for javax.swing DefaultComboBoxModel DefaultComboBoxModel

Introduction

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

Prototype

public DefaultComboBoxModel() 

Source Link

Document

Constructs an empty DefaultComboBoxModel object.

Usage

From source file:Main.java

public static void main(final String args[]) {
    final DefaultComboBoxModel<String> model = new DefaultComboBoxModel<String>();

    model.addElement("A");
    model.addElement("C");
    model.addElement("D");
    model.addElement("E");

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JComboBox<String> comboBox1 = new JComboBox<String>(model);
    comboBox1.setMaximumRowCount(5);//from   ww  w . ja  va  2s  .  c  om
    comboBox1.setEditable(true);
    frame.add(comboBox1, BorderLayout.NORTH);

    JList<String> jlist = new JList<String>(model);
    JScrollPane scrollPane = new JScrollPane(jlist);
    frame.add(scrollPane, BorderLayout.CENTER);

    JButton button = new JButton("Add");
    frame.add(button, BorderLayout.SOUTH);
    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            model.addElement("a");
        }
    };
    button.addActionListener(actionListener);

    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(final String args[]) {
    final DefaultComboBoxModel<String> model = new DefaultComboBoxModel<String>();

    model.addElement("A");
    model.addElement("C");
    model.addElement("D");
    model.addElement("A");

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JComboBox<String> comboBox1 = new JComboBox<String>(model);
    comboBox1.setMaximumRowCount(5);/*  ww w.j  a  va 2s.  c  o  m*/
    comboBox1.setEditable(true);
    frame.add(comboBox1, BorderLayout.NORTH);

    JList<String> jlist = new JList<String>(model);
    JScrollPane scrollPane = new JScrollPane(jlist);
    frame.add(scrollPane, BorderLayout.CENTER);

    JButton button = new JButton("Add");
    frame.add(button, BorderLayout.SOUTH);
    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            model.addElement("a");
            System.out.println(model.getIndexOf("A"));
        }
    };
    button.addActionListener(actionListener);

    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(final String args[]) {
    final DefaultComboBoxModel<String> model = new DefaultComboBoxModel<String>();

    model.addElement("A");
    model.addElement("C");
    model.addElement("D");
    model.addElement("A");

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JComboBox<String> comboBox1 = new JComboBox<String>(model);
    comboBox1.setMaximumRowCount(5);/*from www  .  j a v  a 2 s.c  o  m*/
    comboBox1.setEditable(true);
    frame.add(comboBox1, BorderLayout.NORTH);

    JList<String> jlist = new JList<String>(model);
    JScrollPane scrollPane = new JScrollPane(jlist);
    frame.add(scrollPane, BorderLayout.CENTER);

    JButton button = new JButton("Add");
    frame.add(button, BorderLayout.SOUTH);
    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            model.addElement("a");
            System.out.println(model.getSelectedItem());
        }
    };
    button.addActionListener(actionListener);

    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(final String args[]) {
    final DefaultComboBoxModel<String> model = new DefaultComboBoxModel<String>();

    model.addElement("A");
    model.addElement("C");
    model.addElement("D");
    model.addElement("A");

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JComboBox<String> comboBox1 = new JComboBox<String>(model);
    comboBox1.setMaximumRowCount(5);/*from w w w. j  a va2 s. c  om*/
    comboBox1.setEditable(true);
    frame.add(comboBox1, BorderLayout.NORTH);

    JList<String> jlist = new JList<String>(model);
    JScrollPane scrollPane = new JScrollPane(jlist);
    frame.add(scrollPane, BorderLayout.CENTER);

    JButton button = new JButton("Add");
    frame.add(button, BorderLayout.SOUTH);
    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            model.addElement("a");
            System.out.println(model.getSize());
        }
    };
    button.addActionListener(actionListener);

    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(final String args[]) {
    final DefaultComboBoxModel<String> model = new DefaultComboBoxModel<String>();

    model.addElement("A");
    model.addElement("C");
    model.addElement("D");
    model.addElement("A");

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JComboBox<String> comboBox1 = new JComboBox<String>(model);
    comboBox1.setMaximumRowCount(5);//from   w w w .  j a  v a  2 s  . c om
    comboBox1.setEditable(true);
    frame.add(comboBox1, BorderLayout.NORTH);

    JList<String> jlist = new JList<String>(model);
    JScrollPane scrollPane = new JScrollPane(jlist);
    frame.add(scrollPane, BorderLayout.CENTER);

    JButton button = new JButton("Add");
    frame.add(button, BorderLayout.SOUTH);
    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            model.addElement("a");
            model.insertElementAt("Z", 0);
        }
    };
    button.addActionListener(actionListener);

    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(final String args[]) {
    final DefaultComboBoxModel<String> model = new DefaultComboBoxModel<String>();

    model.addElement("A");
    model.addElement("C");
    model.addElement("D");
    model.addElement("A");

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JComboBox<String> comboBox1 = new JComboBox<String>(model);
    comboBox1.setMaximumRowCount(5);//from w  w w  .j a  v  a 2  s. co m
    comboBox1.setEditable(true);
    frame.add(comboBox1, BorderLayout.NORTH);

    JList<String> jlist = new JList<String>(model);
    JScrollPane scrollPane = new JScrollPane(jlist);
    frame.add(scrollPane, BorderLayout.CENTER);

    JButton button = new JButton("Add");
    frame.add(button, BorderLayout.SOUTH);
    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            model.addElement("a");
            System.out.println(model.getElementAt(1));
        }
    };
    button.addActionListener(actionListener);

    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(final String args[]) {
    final DefaultComboBoxModel<String> model = new DefaultComboBoxModel<String>();

    model.addElement("A");
    model.addElement("C");
    model.addElement("D");
    model.addElement("A");

    model.removeElement("A");

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JComboBox<String> comboBox1 = new JComboBox<String>(model);
    comboBox1.setMaximumRowCount(5);// w w  w  .  j  a va2  s  . c om
    comboBox1.setEditable(true);
    frame.add(comboBox1, BorderLayout.NORTH);

    JList<String> jlist = new JList<String>(model);
    JScrollPane scrollPane = new JScrollPane(jlist);
    frame.add(scrollPane, BorderLayout.CENTER);

    JButton button = new JButton("Add");
    frame.add(button, BorderLayout.SOUTH);
    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            model.addElement("a");
            model.insertElementAt("Z", 0);
        }
    };
    button.addActionListener(actionListener);

    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(final String args[]) {
    final DefaultComboBoxModel<String> model = new DefaultComboBoxModel<String>();

    model.addElement("A");
    model.addElement("C");
    model.addElement("D");
    model.addElement("A");

    model.removeAllElements();//from  ww w.  j av a  2s .co m

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JComboBox<String> comboBox1 = new JComboBox<String>(model);
    comboBox1.setMaximumRowCount(5);
    comboBox1.setEditable(true);
    frame.add(comboBox1, BorderLayout.NORTH);

    JList<String> jlist = new JList<String>(model);
    JScrollPane scrollPane = new JScrollPane(jlist);
    frame.add(scrollPane, BorderLayout.CENTER);

    JButton button = new JButton("Add");
    frame.add(button, BorderLayout.SOUTH);
    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            model.addElement("a");
            model.insertElementAt("Z", 0);
        }
    };
    button.addActionListener(actionListener);

    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(final String args[]) {
    final DefaultComboBoxModel<String> model = new DefaultComboBoxModel<String>();

    model.addElement("A");
    model.addElement("C");
    model.addElement("D");
    model.addElement("A");

    model.setSelectedItem("C");

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JComboBox<String> comboBox1 = new JComboBox<String>(model);
    comboBox1.setMaximumRowCount(5);/*w  ww . ja  v a  2  s .  c  o  m*/
    comboBox1.setEditable(true);
    frame.add(comboBox1, BorderLayout.NORTH);

    JList<String> jlist = new JList<String>(model);
    JScrollPane scrollPane = new JScrollPane(jlist);
    frame.add(scrollPane, BorderLayout.CENTER);

    JButton button = new JButton("Add");
    frame.add(button, BorderLayout.SOUTH);
    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            model.addElement("a");
            model.insertElementAt("Z", 0);
        }
    };
    button.addActionListener(actionListener);

    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(final String args[]) {
    final DefaultComboBoxModel<String> model = new DefaultComboBoxModel<String>();

    model.addElement("A");
    model.addElement("C");
    model.addElement("D");
    model.addElement("A");

    model.removeElementAt(1);//www .  j  a v a 2  s  .c  o  m

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JComboBox<String> comboBox1 = new JComboBox<String>(model);
    comboBox1.setMaximumRowCount(5);
    comboBox1.setEditable(true);
    frame.add(comboBox1, BorderLayout.NORTH);

    JList<String> jlist = new JList<String>(model);
    JScrollPane scrollPane = new JScrollPane(jlist);
    frame.add(scrollPane, BorderLayout.CENTER);

    JButton button = new JButton("Add");
    frame.add(button, BorderLayout.SOUTH);
    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            model.addElement("a");
            model.insertElementAt("Z", 0);
        }
    };
    button.addActionListener(actionListener);

    frame.setSize(300, 200);
    frame.setVisible(true);
}