开发者

In-place switching between swing components

开发者 https://www.devze.com 2023-04-13 05:39 出处:网络
In my swing application, I would like to display the same date using JTree and JTable. Components should be displayed/shown interchangeably, depending on user choice (for example with toggle button).

In my swing application, I would like to display the same date using JTree and JTable. Components should be displayed/shown interchangeably, depending on user choice (for example with toggle button). If button is pressed then JTree should be shown, if not then JTable. The Question: How to do it in proper way. I have tried stacklayout, displaying next/previous component, but it does not seem to be good solution. Both component takes memory, both exists simultaneously. Second solution, in may opinion, is to remove component from panel, and create new one. It can be also memory/time co开发者_StackOverflow中文版nsuming. Do you have any propositions or solutions.


CardLayout seems to be the best fit for this, but it will of course also keep both components in memory. Do you actually have any indication that this is a problem, or are you just suffering from premature optimization worries?


Removing existing components and adding new components to a panel should not be that much of a problem performance-wise. And if you make sure that there is no references to the removed objects (your JTree for example), you should not have any memory problems.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号