简体   繁体   中英

How to get not null Runtime created components names after setName(String);?

I´m building a swing aplication , which has all visual components runtime created on a single class. Every control shows fine. Any time a component is declared, a component.setName(String); is placed. The problem is that when trying to access that names, via component.getName(); , even within the same class instance, I get null result.

for(Component c:this.getFrame().getComponents()) {
    System.out.println(c.getName());
}

getFrame is just an standar getter returning main Jframe. That just print one null, but frame is populated with components.

Expected result should be fe "Calculate" instead of null

it´s been a while: I think I have find the way to solve this q, anyway feedback´swelcome. I´m afraid it was my fault, cause i didn´t explained well the problem. The point are containers (readJFrames, JPanel or whatever). If you´ve got a JPanel inside, let´s say a JFrame, you´ll have to call getComponents of that panel, and so on... Hope it solves the q. Thanks anybody who kept on.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM