I am having trouble with this.
The situation is not difficult to imagine, so I hope to publish it without a code sample. I have a JPanel with CardLayout. The panel contains several other panels as separate tabs. What I'm trying to achieve is to create a JButton that will make the main panel display the last open tab (the one that was shown before the current one started). At first, I did not think that this was not so.
So, I started thinking about how to get the current visible tab (panel), and found out that there is no native method for this in Panel or, rather, CardLayout, which contains only the first (), last (), next () and previous () that don't suit me.
Then I thought that, perhaps, to achieve my goal, I could go through all the components of the main panel and check which one will be visible, which will be current. It seems to me that this is a little complicated, fine, but how can I do this CardLayout group show if I don’t have my card name to call the CardLayout display method (parent, name)?
At this moment I have no idea. I searched through the Internet, but did not find a solution, only a few people tried to understand something like that. Therefore, I hope that someone who is already dealing with this issue is faced with this topic :-)
Thanks for any suggestions.
Regards
Martin S.
source
share