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

Was it helpful?

Solution

Not code but steps that can help you..

  1. Create a Table.
  2. 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.
  3. Repeat step 2 for all hashmap keys.

References that can help you:-

  1. Adding row in table
  2. Adding comboBox in table
  3. JTable add/remove rows to custom table model (updating table display)

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top