I've been looking at this question: How to get all elements inside a JFrame?
and a member of stackoverflow (@aioobe) uses this code taken from http://www.java2s.com/Code/Java/Swing-JFC/GetAllComponentsinacontainer.htm :
public static List<Component> getAllComponents(final Container c) {
Component[] comps = c.getComponents();
List<Component> compList = new ArrayList<Component>();
for (Component comp : comps) {
compList.add(comp);
if (comp instanceof Container)
compList.addAll(getAllComponents((Container) comp));
}
return compList;
}
Now I don't actually know why it worked for the guy who needed help, but it tells me "type List does not take parameters" (using NetBeans 8.0.2). I've been reading some documents about the List object but I couldn't get it. How can I solve this problem? In my program I have a JFrame
with 4 JPanel
on it, and one of those panels has a java.awt.List
on it. I need to get it to assign it to another variable List txt. If you can find a better way to do this, no problem, it would be even greater. Thank you!
This is my frame: