List of usage examples for javax.swing JComboBox setEditable
@BeanProperty(preferred = true, description = "If true, the user can type a new value in the combo box.") public void setEditable(boolean aFlag)
JComboBox
field is editable. From source file:Main.java
public static void main(final String args[]) { final String labels[] = { "A", "B", "C", "D", "E" }; final DefaultComboBoxModel<String> model = new DefaultComboBoxModel<String>(labels); 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 va 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"); } }; button.addActionListener(actionListener); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(final String args[]) { String labels[] = { "A", "B", "C", "D", "E" }; final DefaultComboBoxModel model = new DefaultComboBoxModel(labels); JFrame frame = new JFrame("Shared Data"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(); JComboBox comboBox1 = new JComboBox(); comboBox1.setModel(model);/*from www . j a v a 2 s . co m*/ comboBox1.setMaximumRowCount(5); comboBox1.setEditable(true); JComboBox comboBox2 = new JComboBox(model); comboBox2.setMaximumRowCount(5); comboBox2.setEditable(true); panel.add(comboBox1); panel.add(comboBox2); frame.add(panel, BorderLayout.NORTH); frame.setSize(300, 200); frame.setVisible(true); }
From source file:SharedDataSample.java
public static void main(String args[]) { final String labels[] = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J" }; final DefaultComboBoxModel model = new DefaultComboBoxModel(labels); JFrame frame = new JFrame("Shared Data"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); JPanel panel = new JPanel(); JComboBox comboBox1 = new JComboBox(model); comboBox1.setMaximumRowCount(5);/* www .ja va2 s. co m*/ comboBox1.setEditable(true); JComboBox comboBox2 = new JComboBox(model); comboBox2.setMaximumRowCount(5); comboBox2.setEditable(true); panel.add(comboBox1); panel.add(comboBox2); contentPane.add(panel, BorderLayout.NORTH); JList jlist = new JList(model); JScrollPane scrollPane = new JScrollPane(jlist); contentPane.add(scrollPane, BorderLayout.CENTER); JButton button = new JButton("Add"); contentPane.add(button, BorderLayout.SOUTH); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { int index = (int) (Math.random() * labels.length); model.addElement(labels[index]); } }; button.addActionListener(actionListener); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) throws Exception { Color colors[] = { Color.GREEN, Color.ORANGE, Color.PINK, Color.RED, Color.WHITE, Color.YELLOW }; JFrame frame = new JFrame("Color JComboBox"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JComboBox comboBox = new JComboBox(colors); comboBox.setMaximumRowCount(5);//from w w w . java2 s . co m comboBox.setEditable(true); comboBox.setRenderer(new ColorCellRenderer()); frame.add(comboBox, BorderLayout.NORTH); final JLabel label = new JLabel(); label.setOpaque(true); label.setBackground((Color) comboBox.getSelectedItem()); frame.add(label, BorderLayout.CENTER); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { Color selectedColor = (Color) comboBox.getSelectedItem(); label.setBackground(selectedColor); } }; comboBox.addActionListener(actionListener); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) throws Exception { String[] items = new String[] { "", "Apple", "Banana", "Carrot" }; Color bgColor = UIManager.getColor("TextField.background"); UIManager.put("ComboBox.selectionBackground", new ColorUIResource(bgColor)); JComboBox<String> combo1 = new JComboBox<>(items); combo1.setPrototypeDisplayValue("XXXXXXXXXXXXXXX"); combo1.setEditable(true); combo1.setSelectedIndex(-1);// w w w. j a v a 2 s .c om JComboBox<String> combo2 = new JComboBox<>(items); combo2.setPrototypeDisplayValue("XXXXXXXXXXXXXXX"); combo2.setEditable(false); combo2.setSelectedIndex(-1); combo2.setBackground(bgColor); JFrame frame = new JFrame(); Container c = frame.getContentPane(); c.setLayout(new FlowLayout()); c.add(combo1); c.add(combo2); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(200, 100); frame.setLocationRelativeTo(null); 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("E"); 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 v a2 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"); } }; button.addActionListener(actionListener); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(final String args[]) { Vector<String> vec = new Vector<String>(); vec.add("a"); vec.add("b"); vec.add("c"); final DefaultComboBoxModel<String> model = new DefaultComboBoxModel<String>(vec); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JComboBox<String> comboBox1 = new JComboBox<String>(model); comboBox1.setMaximumRowCount(5);/*from w ww. java 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"); } }; 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 ava 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);// w w w. j a va 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.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 ava 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"); System.out.println(model.getSize()); } }; button.addActionListener(actionListener); frame.setSize(300, 200); frame.setVisible(true); }