comboboxmodel

How to update JComboBox instances in Swing?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-01 00:40:24
I've 3 comboboxes, upon selecting first combobox, the rest should be updated but my code doesn't seems to be working. Please help in this guys. Here is my code(since my code very long so I'll write error part only). // example code public class GuiComponents { JComboBox<String> comboBox1, comboBox2, comboBox3; public GuiComponents() { ......... ......... String[] element1 = {"item1", "item2", "item3"}; String[] element2 = {"item1", "item2", item3}; String[] element3 = {"item1", "item2", "item3"}; comboBox1.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent

Sharing same model between two JComboBoxes

浪尽此生 提交于 2019-11-29 12:21:43
I have a Person [ ] with three Persons (p1,p2,p3). Person class has two attributes name and email . I want to add all names of Person[] in one JComboBox and all emails in another JComboBox. I used the following code. Person p1 = new Person("Smith", "smith@mail.com"); Person p2 = new Person("Tom", "tom@gmail.com"); Person p3 = new Person("John","john@mail.com"); Person[] per_arr = new Person[] { p1, p2, p3}; JFrame frame = new JFrame(); JPanel panel = new JPanel(); JComboBox<String> combo1 = new JComboBox<String>(); JComboBox<String> combo2 = new JComboBox<String>(); for (Person p : per_arr) {

Sharing same model between two JComboBoxes

爷,独闯天下 提交于 2019-11-28 05:55:00
问题 I have a Person [ ] with three Persons (p1,p2,p3). Person class has two attributes name and email . I want to add all names of Person[] in one JComboBox and all emails in another JComboBox. I used the following code. Person p1 = new Person("Smith", "smith@mail.com"); Person p2 = new Person("Tom", "tom@gmail.com"); Person p3 = new Person("John","john@mail.com"); Person[] per_arr = new Person[] { p1, p2, p3}; JFrame frame = new JFrame(); JPanel panel = new JPanel(); JComboBox<String> combo1 =