简体   繁体   中英

JTabbedPane adding null components

Riddle me this: I have a JTabbedPane that has custom JPanels in it. When I try and access those JPanels, all I get back is null. I know that the panels have been added because on the UI I can see the tabs. I can also interact with the panels and switch between tabs. It doesn't matter how I add these JPanels, it always returns null.

Now I could just keep an ArrayList of the JPanels on the side for processing, but I would think that would kinda defeat the purpose of the JTabbedPane keeping any kind of model.

Does anyone know what's going on with this?

You're using the wrong method: getTabComponentAt(int) will return the Component used to render the actual tab itself (if you've specified one). You should call getComponentAt(int) instead. I've done exactly the same thing myself before!

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