2

I was wondering if there was a way to make one component (in this case a JPanel) visible in more than one of the tabs.

I have a simple JFrame which is completely filled with a JTabbedPane. Each tab has a slightly different function, which is why they're in different tabs. However, they each output the same type of information. I was wondering if there was a way to make it so the same output panel could be seen in all the tabs, without having to create one panel for each tab.

I realize that it is impossible to add one component multiple times (and have it display independently each time), which is why I'm not optimistic about this being possible, however if it is, it would make my code much cleaner. In the case that this is not possible, I am completely open to alternate suggestions that achieve a similar result. I am in the very beginning of my project, so it won't be too difficult to change things.

This image gives a rough idea of what I'm trying to make it look like:

https://i.stack.imgur.com/jLUGa.png

I have searched around for anyone dealing with this issue, however I have had little luck finding anything relevant. If I missed something, I apologize for wasting your time.

camickr
  • 321,443
  • 19
  • 166
  • 288
Aragorn Crozier
  • 364
  • 2
  • 12
  • 5
    You can't. A component can only have a single parent. `each output the same type of information.` - so create multiple panels and just update the information on the panel. The other option is to not have the "output panel" as part of the table. So maybe the tabbed pane is added to the the CENTER of the BorderLayout of the frame and the "output panel" is added to the LINE_END. Then as you switch from tab to tab you need to refresh the "output panel" with the appropriate information. – camickr May 14 '17 at 19:38
  • 6
    Components can share a model, but perhaps the best approach for this is to put the panel with the labels **beside** (i.e. outside) the tabbed pane. – Andrew Thompson May 14 '17 at 19:41

0 Answers0