views:

94

answers:

1

Hi Everyone,
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?

+6  A: 

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!

Adamski
That was exactly it. Thanks :)
Robbie