Java 查找Panel 里的某个组件 比如 按钮
2024-10-22 04:47:40
遇到到一个需求,需要获取界面里的一个按钮,但是这个按钮是封装的父类嵌入的,知道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 }
最新文章
- CentOS设置默认启动命令行(不启动图形界面)
- 兼容ie的jquery ajax文件上传
- android 入门-R文件的死与活
- matrix_last_acm_3
- switch..case函数的基础使用一
- 1、Web容器的理解&;Tomcat的安装与配置
- 可恶的QT隐式共享
- error:stray&;#39;\243&;#39;in program
- Android打开系统设置
- 3.更改ssh服务远程登录的配置
- Oracle 11gR2 客户端windows 10安装后PL/SQL配置
- Python 构建工具 buildout 的介绍与使用
- 067 HA与updateStateByKey结合
- .NET并行计算和并发8-QueueUserWorkItem异步
- gist.github.com 被墙无法访问解决办法
- 二分法求平方根(Python实现)
- ES6的Promise对象
- IP地址分配机构
- 《快学Scala》
- Yosemite 给 iOS 录屏