多层 JPanel。想要重新粉刷中间面板而不覆盖更多的前面板

发布于 2024-12-14 00:03:39 字数 435 浏览 2 评论 0原文

我正在制作一个游戏。它由一个 JPanel 组成,该 JPanel 包含几个其他 JPanel。 1 个带有按钮的底部面板,1 个带有按钮的顶部面板,这两个面板之间的一个面板是常规游戏屏幕,然后是几个通过单击顶部或底部面板上的按钮滑入或弹出的 SlidingPanes 和动态 JPanel或者点击游戏屏幕上的某个位置。

现在,我正在绘制一辆沿着游戏屏幕上的路径行驶的卡车。卡车绘制得很好,但每当我单击按钮打开滑动窗格时,它就会被游戏屏幕面板吸引,使其在打开时闪烁,然后直到我将鼠标悬停在它上面时才会显示。游戏屏幕的paintComponent方法就是造成这种情况的原因,每当调用它的重绘方法时,当我希望它留在滑动窗格或在其顶部弹出的面板后面时,它就会将游戏屏幕带到前面。

有没有办法让游戏屏幕保持在原来的层而不用paintComponent将其带到顶部?

如果您有任何疑问,请告诉我。

谢谢

I am making a game. It consists of a JPanel that contains several other JPanels. 1 bottom panel, with buttons, 1 top panel, with buttons, one panel in between those two panels that is the regular Game screen, and then several SlidingPanes and dynamic JPanels that slide in or pop up from clicking buttons on the top or bottom panel or from clicking somewhere on the game screen.

Right now, I am drawing a truck that follows a path on the game screen. The truck draws fine, but whenever I click a button to open the sliding pane, it gets drawn over by the Game Screen panel, making it flicker as it opens and then not show until I mouse over it. The Game Screens paintComponent method is the cause of this, it is bringing the Game Screen to the front whenever it's repaint method is called, when I want it to stay behind the Sliding Panes or panels that pop up on top of it.

Is there a way to make the game screen stay at the layer it is without paintComponent bringing it to the top?

Please let me know if you have any questions.

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文