Netbeans GUI 组件修改后不会更新

发布于 2024-10-21 05:52:48 字数 294 浏览 1 评论 0原文

我找不到遇到同样问题的人,所以这可能只是一个简单的修复,但我正在 Netbeans 中创建 Jeopardy 游戏。我创建了一个 JPanel 表单来设计每个单独的方块,然后将其中的 36 个(对于 6x6 板)添加到代表该板的另一个 JPanel 表单中。这很好用,但问题是,当我将所有 36 个方块添加到棋盘上后,它们会停留在我添加它们时的状态。如果我更改 Question JPanel 表单中标签的位置或颜色,它不会在 Jeopardy Board JPanel 表单中更新。我不想每次更改子组件时都重新添加 36 个问题并重命名所有变量。有没有办法让一切保持同步?

I can't find anyone who has this same problem, so it might just be a simple fix, but I'm creating a Jeopardy game in Netbeans. I created a JPanel Form to design each of the individual squares, and then I added 36 of them (for the 6x6 board) to another JPanel Form which represents the board. That works great, but the problem is that after I add all 36 squares to the board, they are stuck in the state at which I added them. If I change the position or color of a label in the Question JPanel Form, it does not update in the Jeopardy Board JPanel Form. I don't want to re-add 36 Questions and rename all the variables every time I make a change to a sub-component. Is there a way to keep it all in sync?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

等待圉鍢 2024-10-28 05:52:48

如果我更改问题 JPanel 表单中标签的位置或颜色,

1)。标签是不透明的,这意味着更改背景颜色不会产生任何效果。当您想要更改背景时,您需要在创建标签时将其设置为不透明:

label.setOpaque( true );

2)一旦设置了危险板,您就不需要更改标签的位置。一旦问题得到解答,我只需使用以下方法清除标签中的文本:

label.setText("");

对于每一轮新的危险,您需要做的就是重置每个标签的背景,然后重置每个标签的文本。不需要重新创建所有标签。

If I change the position or color of a label in the Question JPanel Form,

1). labels are non opaque which means changing the background color will have no effect. You need to make the label opaque when you create it when you want to alter the background:

label.setOpaque( true );

2) Once you set up your jeopardy board you should have no need to change the position of the label. Once the question is answer, I would just clear the text in the label by using:

label.setText("");

For each new round of jeopardy again all you need to do is reset the background for every label and then reset the text for every label. There should be no need to recreate all the labels.

渡你暖光 2024-10-28 05:52:48

您可以尝试调用 JPanel 的 revalidate() 方法。

You could try calling the revalidate() method of the JPanel.

热鲨 2024-10-28 05:52:48

考虑重构和重命名您在项目中亲自创建的所有文件夹。这应该可以解决问题。

Consider refactoring and renaming all folders you personally created in the project. This should resolve the issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文