3

I have JTabbedPane with many generated dynamically JPanels, that contains JTable. How can i get/set JTable from the selected JTabbedPane tab?

Already tried to use JTabbedPane.getComponents(), but it doesn't contain any JTable components.

crzbt
  • 183
  • 4
  • 14

1 Answers1

3
myPane.getSelectedComponent().getComponents();

will give you all components of the selected tab's component. You can search with a loop for the class JTable, if there is more than 1 component in your JPanel.

Leo Pflug
  • 544
  • 3
  • 15
  • 1
    Your answer helped me to find it in google. There's JScrollPane inside of TabbedPane, which has ViewPort. And that ViesvPort method gives castable JTable JScrollPane scrollPane = (JScrollPane) (jTabbedPane.getSelectedComponent()); JViewport viewport = scrollPane.getViewport(); JTable mytable = (JTable)viewport.getView(); – crzbt Nov 22 '13 at 13:33
  • 2
    Indeed, most people use a JScrollPane as a container for their JTable ... That's why giving a SSCCE is important, because I can't guess that you're using a JScrollPane, if you're only talking about a TabbedPane and a JTable. – Leo Pflug Nov 22 '13 at 13:40