简体   繁体   English

CardLayout不能完全隐藏其他卡吗?

[英]CardLayout not completely hiding other cards?

I am building a game, and to switch between the login screen and the game screen, I am using a CardLayout . 我正在构建游戏,并且要在登录屏幕和游戏屏幕之间切换,我使用CardLayout

The code I am using to switch between the screens is 我用来在屏幕之间切换的代码是

Global.gameScreen = new GameScreen(Global.connectionHandler.clientSocket);
cards.add(Global.gameScreen,"gameScreen");
((CardLayout)cards.getLayout()).show(cards,"gameScreen");

What happens, though is after I switch the screen, if I move my mouse over where the Swing controls in the login screen were, they appear and I can interact with them. 虽然发生了什么,但是在我切换屏幕之后,如果将鼠标移到登录屏幕中Swing控件所在的位置,它们就会出现,并且我可以与它们进行交互。

Is there a specific way I should switch cards? 是否有我应该更换卡的特定方法?

I solved the problem by simply adding 我通过简单地添加来解决了这个问题

getContentPane().remove(cards);
getContentPane().add(cards, BorderLayout.CENTER);

I don't know if this is the right way to solve it, but it worked for me. 我不知道这是否是解决问题的正确方法,但这对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM