0

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?

Robbie
  • 831
  • 2
  • 14
  • 22
  • Please can you add the code to show how you are adding the JPanels and how trying to 'access those JPanels'. – Nick Holt Aug 13 '09 at 14:18
  • conversationTabs is the JTabbedPane. conversationTabs.getTabComponentAt(i) I'm adding the tabs like so: conversationTabs.addTab("Blah", (instance of the JPanel)) conversationTabs.insertTab("Blah", null, (instance of the JPanel), "", 0) – Robbie Aug 13 '09 at 14:19

1 Answers1

6

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
  • 54,009
  • 15
  • 113
  • 152