-1

I'm looking for a way to clone (duplicate) a whole tab (the selected one) in a JTabbedPane. Every time I take the tabwith getSelectedComponent() and add it to the pane, the title of the tab disapnö rs and I get no second tab. But there is no exception.

I tried to copy the currently selected tab. Each tab is a JPanel with a simple JTable on it and I want to get the selected tab two times.

kleopatra
  • 51,061
  • 28
  • 99
  • 211

2 Answers2

0

As far as I know, the same swing component can't appear in multiple places in your GUI, so you would actually have to create new instances of all your UI elements for the "copied" tab and set their values to the same values of the first tab / connect them to the same domain objects.

David
  • 1,359
  • 1
  • 13
  • 20
  • I solved it now with a tmp-file... Writing the data to it and create a New tab and add the data in a second tab... In my opinion not the Best solution, but it works . Thx 4 help =) – Tobi Fiehlmann Jun 14 '13 at 11:30
  • Why use a tmp file? Why not just read the content from the GUI elements in the first tab and put it in the components in the second tab? – David Jun 15 '13 at 18:27
0

In Swings, a component can be added to only one container. Adding it again to another container will have no effect.

Mubin
  • 4,192
  • 3
  • 26
  • 45