gpt4 book ai didi

java - 如何获取 JSplitPane 的特定组件?

转载 作者:行者123 更新时间:2023-12-01 11:05:55 25 4
gpt4 key购买 nike

这个想法是获取 JSplitPane 的特定组件,例如:

JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, panel1, panel2);

有没有办法从对象splitPane获取panel1panel2

最佳答案

您可以获得容器内所有组件的数组(JSplitPane 是一个容器):

    // 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());
}

关于java - 如何获取 JSplitPane 的特定组件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32951103/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com