首页 > 编程语言 >Java 查找Panel 里的某个组件 比如 按钮

Java 查找Panel 里的某个组件 比如 按钮

时间:2023-02-14 17:36:19浏览次数:36  
标签:container tmpBtn label return 按钮 Java JButton Panel

遇到到一个需求,需要获取界面里的一个按钮,但是这个按钮是封装的父类嵌入的,知道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     }

 

标签:container,tmpBtn,label,return,按钮,Java,JButton,Panel
From: https://www.cnblogs.com/wn2ln/p/17120295.html

相关文章

  • Java入门
    Java特性与优势简单性面向对象可移植性(跨屏台)高性能分布式动态性(反射)多线程安全性健壮性Java的三大版本JavaSE:标准版(桌面程序、控制台......
  • vue实现自定义多选按钮
    html部分<div:class=""getSxxClass(item)v-for="(item,index)indata.sxxList":key="index"@click="sxxchangeQuery(item)"></div>js部分constdata=reactive......
  • 【开发宝典】Java并发系列教程(四)
    作者:京东零售刘跃明Monitor概念Java对象的内存布局对象除了我们自定义的一些属性外,还有其它数据,在内存中可以分为三个区域:对象头、实例数据、对齐填充,这三个区域组成起来才......
  • java深拷贝和浅拷贝介绍
    浅拷贝概念  深拷贝概念@Data@Slf4jpublicclassSheepimplementsCloneable{privateStringname;privateintage;privateStringcolor;privateShe......
  • jvm优化base java GC垃圾回收
    OutOfMemoryError错误Java堆内存的OutOfMemoryError异常是实际应用中常见的内存溢出异常情况。当出现Java堆内存溢出时,异常堆栈信息“java.lang.OutOfMemoryError”会跟着......
  • Java 之 invokedynamic
    简述Addanewbytecode,invokedynamic,thatsupportsefficientandflexibleexecutionofmethodinvocationsintheabsenceofstatictypeinformation.--JSR......
  • JAVA和Spring的SPI机制讲解
    目录1SPI机制讲解1.1引言1.2JavaSPI实现1.2.1示例说明1.2.2相关测试1.2.3源码分析1.3SpringSPI1.3.1Spring示例1.3.2相关测试类1.3.3源码分析1SPI机制讲解......
  • JavaScript对象属性的特性高级功能
    “usestrict”/创建一个对象最简单的方式:创建一个Object的实例,然后再为它添加属性和方法/varperson=newObject();person.name=“Hongbin”;person.age=21;per......
  • java连接数据库实现增删改查功能
    packagecom.atguigu.api.preparedstatement;importorg.junit.Test;importjava.sql.*;importjava.util.Scanner;publicclassPreparedStatement_CRUD_Test{//TODO......
  • 3d按钮实现
    以上的效果都来自于css3废话不多说,代码如下点击查看代码div{width:100px;height:40px;background-color:#1a5bd4;position:absolute;......