Reputation: 3526
I am looking to achieve something like this, represented in the image:
Basically it's a list, but with two columns. The first column's rows are just labels or textfields, and the second column is filled with JComboBox. Is there already something like this built in to java?
Thanks a lot in advance!
Upvotes: 0
Views: 72
Reputation: 813
I would make a generic object that you could use to store 2 object instances or 2 new ArrayLists of any kind.
public class DoubleList<T1,T2>
{
final public ArrayList<T1> listOne = new ArrayList<T1>();
final public ArrayList<T2> listTwo = new ArrayList<T2>();
}
With this class, you can easily make use of it as follows:
DoubleList<Label, ComboBox> myCustomList = new DoubleList<Label, ComboBox>();
//Ready to use the lists by
//myCustomList.listOne and myCustomList.listTwo
The other alternative is:
public class DoubleObjects<T1,T2>
{
final public T1 one = new T1();
final public T2 two = new T2();
}
and use:
ArrayList<DoubleObjects<Label, ComboBox>> arrayList = new ArrayList<DoubleObjects<Label, ComboBox>>();
Upvotes: -1
Reputation: 347314
Yes, see How to use tables, in particular the section on Using a Combo Box as an Editor
Upvotes: 4