How to store multiple values in a JTable row as a JCombobox
-
15-11-2019 - |
Question
Hashmap contains key and value(result of parsing an XML). Hashmap contains things in the way that key is a string and value is a vector. A key may have single value in the vector or mutiple values in the vector.
My question is:
This hashmap, has to be put into a jtable,such that if the key has single value, put it to text box. If it has multiple values insert a combobox in the row of that table.
I need the swing code for this problem
Solution
Not code but steps that can help you..
- Create a Table.
- Every time adding a new row check for the hashmap value and if it is a single value add textbox to that cell or add comboBox.
- Repeat step 2 for all hashmap keys.
References that can help you:-
OTHER TIPS
You can make a HashMap<String, Vector<ValueType>> which maps a String key to a Vector. In this case, even a single value will be stored in a Vector, and when you add the first element for a hash key, you have to make a vector, add the element to it, and put the vector with the key. Subsequently you can just add to the vector. For display, determine if the Vector has 1 or more elements to decide which UI to use.