Java实现遍历窗体上全部组件

/** * call 递归算法实例 ObtainComonent(frame.getContentPane().getComponents()); * descrpt: 实现遍历窗体上全部组件 */ private static void ObtainComonent(Component[] obj) { for (int i = 0; i < obj.length; i++) { if (obj[i] instanceof JPanel) { JPanel panel = (JPanel) obj[i]; ObtainComonent(panel.getComponents()); } else if (obj[i] instanceof Component) { //handler something. System.out.println(obj[i]); } } }

你可能感兴趣的:(Java技术专栏)