如何加载所有控制变量名称,然后编辑它们的属性

时间:2015-03-23 14:59:54

标签: java netbeans

我想加载所有控件变量和示例 Button1的 BUTTON2 BUTTON3

然后编辑他们的属性,如

Button1.settext() ; 

请告诉我他们是这样做的方法。

1 个答案:

答案 0 :(得分:0)

假设您在同一帧中拥有所有这些标签,您可以尝试以下方法:

Arrays.asList(myframe.getComponents()).forEach((c) -> {
    if( c instanceof JLabel) {
        JLabel l = (JLabel)c;
        //do whatever you'd like to do with your label here...
    }
});