In my application, in which I have two JLists, I'm trying to show the contents of the second one depending on what is selected in the first one. Let's say I have group 1, group 2 and group 3 at List1, and when I select Group 1, I want List2 to display what I have at Group 1, and so on. I have actually coded it, and it works, but it gives this warning:
[unchecked] unchecked call to setModel(ListModel<E>) as a member of the raw type JList
exampleGroup2.setModel(group2Container.get(exampleGroup1.getSelectedIndex()));
where E is a type-variable:
E extends Object declared in class JList
1 warning
I've read similar questions, like this one, about generics and so, and they resolved similar problems which gave a similar warning, in which I had to specify the <String>
type, but it doesn't help here.
The line itself, where the warning pops out, is this one:
exampleList2.setModel(list2Container.get(exampleList1.getSelectedIndex()));
Where everything is declarated as:
DefaultListModel<String> list1Container = new DefaultListModel<>();
ArrayList<DefaultListModel<String>> list2Container = new ArrayList<>();
list2Container.add(new DefaultListModel<>());
JList exampleList1 = new JList<>((ListModel<String>) list1Container);
JList exampleList2= new JList<>((ListModel<String>) list2Container.get(0));
Sorry if it's a bit messy, I've tried to make it as short and clear as possible. As I said, I've looked on generics, and so, but I cannot find where should I put the <String>
, or even what do I have to put, in this case.
Thank you very much, for your help.