[英]Get all swing components in a container
I think we can use jScrollPane.getComponents()
to get awt components of a jscrollpane. 我想我们可以使用
jScrollPane.getComponents()
来获取jscrollpane的awt组件。 My question is: is there a way to get swing components of a container some how? 我的问题是:有没有办法让容器的摆动组件如何?
All Swing components extend JComponent. 所有Swing组件都扩展了JComponent。
Component[] comps = jScrollPane.getComponents();
ArrayList<JComponent> swingComps = new ArrayList<JComponent>();
for(Component comp : comps) {
if(comp instanceof JComponent) {
swingComps.add((JComponent) comp);
}
}
You can call getComponents
then test to see if it is an instance of JComponent
. 您可以调用
getComponents
然后测试它是否是JComponent
的实例。 A method would be like: 方法如下:
ArrayList jcomponents = new ArrayList();
for (Component c : container.getComponents())
{
if (c instanceof JComponent)
{
jcomponents.add(c);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.