package com.kingdee.eas.common;
import java.awt.Component;
import java.awt.Container;
import java.util.Hashtable;
public class DepUtil {
/**
*
*
* @param c
* 需要获取控件的父组件
* @param controls
* 需要获取控件的名称数组
* @param found
* 需要填装获取到的控件的集合
*/
public static void findComponent(Component c, String[] controls, Hashtable<String, Component> found) {
Container con = null;
String compName = null;
if (c instanceof Container) {
compName = c.getName();
if (compName != null) {
for (int i = 0; i < controls.length; i++) {
if (compName.equals(controls[i])) {
if (!found.containsKey(compName)) {
found.put(compName, c);
break;
}
}
}
}
if (found.size() != controls.length) {
con = (Container) c;
int count = con.getComponentCount();
for (int i = 0; i < count; i++) {
findComponent(con.getComponent(i), controls, found);
if (found.size() == controls.length)
return;
}
}
}
}
/**
* 获取DEP添加的控件
*
* @param c
* 需要获取控件的父组件
* @param cName
* 需要获取控件的名称
* @return
*/
public static Component findComponent(Component c, String cName) {
Hashtable<String, Component> found = new Hashtable<String, Component>(5);
findComponent(c, new String[] { cName }, found);
if (found.size() > 0) {
return found.get(cName);
}
return null;
}
}
调用方法示例:
DepUtil.findComponent(this.contBizDate.getParent(),new String[]{"pkkDDatePicker"},hs);