If you have an empty combobox model the view should clear automatically. If you derived an own model do not forget to call DefaultComboBoxModel. FireIntervalRemoved() if you remove entries Another (in this case not recommended) way is to use combobox.
SetSelectedItem(null).
If you have an empty combobox model the view should clear automatically. If you derived an own model do not forget to call DefaultComboBoxModel. FireIntervalRemoved() if you remove entries.
Another (in this case not recommended) way is to use combobox. SetSelectedItem(null);.
Regarding the first part, yes that is what I've always thought and now this problem. The funny thing is that the model indicates that there are no items yet the last selected one shows on the UI. – user276002 Apr 9 at 13:57 @user276002 it actually does.So the issue seems to be somewhere else in your code.
Please post the relevant parts such that we can have a look. – Howard Apr 9 at 14:06 Here is a breakdown of my code: I am using JGoodies Binding, so here is the line where I bind the JComboBoxes to the corresponding models: 'Bindings. Bind(combo1, entryrModel.getEntryList()); Bindings.
Bind(combo2, entryModel.getSubEntryList());` – user276002 Apr 9 at 14:36 Here is a breakdown of my code: I am using JGoodies Binding, so here is the line where I bind the JComboBoxes to the corresponding models: Bindings. Bind(combo1, entryrModel.getEntryList()); Bindings. Bind(combo2, entryModel.getSubEntryList()); Here is the action listener for combo1: private final class EntryComboActionListener implements ActionListener { @Override public void actionPerformed(ActionEvent e) { entryModel.
Select((Entry) combo1.getSelectedItem()); } } combo2 has a similar structure.. – user276002 Apr 9 at 14:48.
Replace the model in the second combo box when you make a selection in the first: import java.awt. *; import java.awt.event. *; import java.util.
*; import javax.swing. *; public class ComboBoxTwo extends JFrame implements ActionListener { private JComboBox mainComboBox; private JComboBox subComboBox; private Hashtable subItems = new Hashtable(); public ComboBoxTwo() { String items = { "Select Item", "Color", "Shape", "Fruit" }; mainComboBox = new JComboBox( items ); mainComboBox. AddActionListener( this ); // prevent action events from being fired when the up/down arrow keys are used // mainComboBox.
PutClientProperty("JComboBox. IsTableCellEditor", Boolean. TRUE); getContentPane().
Add( mainComboBox, BorderLayout. WEST ); // Create sub combo box with multiple models subComboBox = new JComboBox(); subComboBox. SetPrototypeDisplayValue("XXXXXXXXXX"); // JDK1.4 getContentPane().
Add( subComboBox, BorderLayout. EAST ); String subItems1 = { "Select Color", "Red", "Blue", "Green" }; subItems. Put(items1, subItems1); String subItems2 = { "Select Shape", "Circle", "Square", "Triangle" }; subItems.
Put(items2, subItems2); String subItems3 = { "Select Fruit", "Apple", "Orange", "Banana" }; subItems. Put(items3, subItems3); // mainComboBox. SetSelectedIndex(1); } public void actionPerformed(ActionEvent e) { String item = (String)mainComboBox.getSelectedItem(); Object o = subItems.
Get( item ); if (o == null) { subComboBox. SetModel( new DefaultComboBoxModel() ); } else { subComboBox. SetModel( new DefaultComboBoxModel( (String)o ) ); } } public static void main(String args) { JFrame frame = new ComboBoxTwo(); frame.
SetDefaultCloseOperation( EXIT_ON_CLOSE ); frame.pack(); frame. SetLocationRelativeTo( null ); frame. SetVisible( true ); } }.
I have two JComboBoxes (call them combo1 and combo2 ) that get their values from a databaseIn the DB, these two have a 1:M relationship. When the screen shows up I populate combo1 with values from the database and then take the first entry in the list and get its corresponding values to populate combo2. Since the values of combo2 depend on what is selected in combo1, every time the selection changes in combo1 a call is made to the database to get matching values to populate combo2.
Say I have two entries in combo1 and the second entry has no corresponding values for combo2. When I select the second entry of combo1, the last selected value on combo2 does not clear. Qeustion: How do I clear the text in combo2 if the model is empty?
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.