遇到到一个需求,需要获取界面里的一个按钮,但是这个按钮是封装的父类嵌入的,知道label 的值。

写了一个递归获取它

 1 private JButton LookupTheButton(Component container, String label)
2 {
3 if (container instanceof JButton)
4 {
5 if (((JButton)container).getText().contains(label))
6 {
7 return ((JButton)container);
8 }
9 }
10 else if (container instanceof Container)
11 {
12 for (Component compt : ((Container)container).getComponents())
13 {
14 JButton tmpBtn = LookupTheButton(compt, label);
15 if (null == tmpBtn)
16 {
17 continue;
18 }
19 else
20 {
21 return tmpBtn;
22 }
23 }
24 }
25
26 return null;
27 }

最新文章

  1. CentOS设置默认启动命令行(不启动图形界面)
  2. 兼容ie的jquery ajax文件上传
  3. android 入门-R文件的死与活
  4. matrix_last_acm_3
  5. switch..case函数的基础使用一
  6. 1、Web容器的理解&Tomcat的安装与配置
  7. 可恶的QT隐式共享
  8. error:stray'\243'in program
  9. Android打开系统设置
  10. 3.更改ssh服务远程登录的配置
  11. Oracle 11gR2 客户端windows 10安装后PL/SQL配置
  12. Python 构建工具 buildout 的介绍与使用
  13. 067 HA与updateStateByKey结合
  14. .NET并行计算和并发8-QueueUserWorkItem异步
  15. gist.github.com 被墙无法访问解决办法
  16. 二分法求平方根(Python实现)
  17. ES6的Promise对象
  18. IP地址分配机构
  19. 《快学Scala》
  20. Yosemite 给 iOS 录屏

热门文章

  1. SSM框架学习-AOP学习笔记
  2. net core api上传下载大文件 413、400错误 IIS服务器
  3. opencv-python 批量更改图像分辨率并且保留图像原有的透明度
  4. 41.Sentinel
  5. 钉钉h5开发流程
  6. 工作日统计工具(python)
  7. UE打LOG整理
  8. API 文档
  9. php 关于 json字符串使用json_decode 转数组为空
  10. awk 计算