I am trying to create an inventory program. And I need help to know how to make
ID: 3640992 • Letter: I
Question
I am trying to create an inventory program. And I need help to know how to make a JComboBox1, a JTextField, and another JComboBox2 work together:For example, in JComboBox1 I have item category; in JComboBox2 i want to display Item description for each category, and in the JTextField i want to display the ID# when an item is selected.
This is the code that I have so far
//add items to jComboBox box;
String[] category = {"Paint Parts", "Trim Out Parts"};
for(int i =0; i< category.length; i++)
box.addItem(category[i]);
//Map to hold Trim Out Parts
final Map<Integer,String > map = new LinkedHashMap<Integer,String>();
map.put(13133, "Nose Plug");
map.put(13000, "Light Kit");
//Map to hold Paint Parts
final Map<Integer, String> paint = new LinkedHashMap<Integer, String>();
paint.put(12103, "Red Primer");
paint.put(12104, "Coal Tar");
Set<Map.Entry<Integer, String>> entrySet = map.entrySet();
for( final Map.Entry<Integer, String> entry: entrySet)
jComboBoxCategory.addItemListener(
new ItemListener(){
public void itemStateChanged(ItemEvent e){
if(e.getStateChange() == ItemEvent.SELECTED)
jComboBoxItemDescription.addItem(entry.getValue());
}
});
The display that I want is;
if user selects Paint Parts, only paint parts should be populated in the jComboBoxItemDescription; and the ID# for the selected item description should be displayed in the JTextField...
I would really appriciate any help, I will rate life saver...
Explanation / Answer
Well, from what you wrote I presume you are a clever computer scientist so I will leave out the code for you to complete, I will leave a pseudo-code/description to consider: you have N maps and you want (combo)Box1 to select ONLY which map to populate other two controls. So you need to keep this in some kind of map: mapRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.