Reputation: 276
The idea would be to get a particular component of a JSplitPane, for example :
JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, panel1, panel2);
Is there a way to get panel1
or panel2
from the Object splitPane
?
Upvotes: 0
Views: 398
Reputation: 5742
You can get an array of all components inside a container (JSplitPane is a container) :
// 2 JPanels for example
JPanel panel1 = new JPanel();
panel1.setName("pan1");
getContentPane().add(panel1);
JPanel panel2 = new JPanel();
panel2.setName("pan2");
getContentPane().add(panel2);
// creating the JSplitPane container with those panels
JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, panel1, panel2);
// get all components from the JSplitPane and print their names
Component[] components=splitPane.getComponents();
for(Component c:components){
System.out.println(c.getName());
}
Upvotes: 1