I have an open source application that use JTabbedPane to show its contents. Look at this screenshot:
The main content has a JSplitPane where at the left side is TreeMenu object and at right side is JTabbedPane object.
When I clicked a menu from the left panel, it will display the menu contents in JTabbedPane by using JTabbedPane.addTab() method:
tabbedPane.addTab(menu.getTitle(), menu.getAPanel());
I need to know how to do this: when I clicked a menu that has an associated tab already opened, it will not add a new tab, instead it should give focus to the already opened tab.
For example, you can see in the screenshot, I had already opened Cost Type tab. Now, if I click the Cost Type menu again, it should bring focus to the Cost Type tab, instead of adding new Cost Type tab.
The menu itself has an unique id field (menu.getId()). However, every time I clicked the menu, the menu.getAPanel() always returned a new instance of APanel. That means if I clicked Cost Type menu two times, the APanel returned from menu.getAPanel() from first click and second click will never be a same instance.
Anyone can help?
UPDATE:
Alright, it seems this question is confusing other people and honestly, I'm not a native english speaker, that's why I had a hard time to explain my problem and I had found the solution anyway (thanks to MadProgrammer), so I'm planning to delete this question as I think it will not benefit the others anymore, but to honor MadProgrammer, I will keep this question open for two days to give him a chance submitting his answer and get his deserved reputation.
Only for a little curious one:
This case has connection with my previous question. In original source code, when the menu is clicked, it actually displays a pop-up window. I'm trying to change the flow to: when the menu is clicked, the pop-up window is hidden and the pop-up window's content panel (APanel) is fetched and transferred into JTabbedPane as tab's component.