Java JFrame 不更新按钮的设置
我目前遇到一个 Java Jframe 和按钮未更新的小问题。
我正在尝试禁用“打印”按钮,直到它打开的新 JFrame 的打印完成并且 JFrame 关闭...
该按钮仅在出现新窗口时才会禁用,但在此之前不会,这可能需要一段时间一点时间......
我通过执行以下操作将按钮设置为禁用: PrintBttn.setEnabled(false);
我尝试调用 mainPanel.revalidate(); mainPanel.repaint(); PrintBttn.revalidate(); PrintBttn.repaint 以及他们在其他论坛中推荐的上述内容的混合...
我现在有点迷失了这一点,以及为什么它不会禁用按钮,直到出现一个新窗口,因为我做的第一件事是如上所示禁用它,然后浏览并创建新窗口......
谢谢, 埃里克
I am currently having a minor issue with a Java Jframe and a button not updating.
I am trying to disable the Print Button until the printing of the new JFrame it opens is done and that JFrame is closed...
The button will only disable if and when a new window occurs, but will not until then, which can take a little bit of time....
I set the button to disable by doing this: PrintBttn.setEnabled(false);
I have tried calling mainPanel.revalidate(); mainPanel.repaint(); PrintBttn.revalidate(); PrintBttn.repaint
as well as a mixture of the above as they recommended in other forums...
I am kind of lost at the moment on this and to why it is not disabling the button until a new window appears since the first thing i do is Disable it as shown above, and then go through and create the new window....
Thanks,
Erik
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最有可能的是释放 EDT 以允许其重新绘制禁用按钮的问题。
一般来说,它看起来像这样:
Most likely, it's a question of releasing the EDT to allow it to repaint the disabled button.
Generally, it will look something like this:
可能您也未能将第一帧放入 EDT,请观看代码,这就是您真正想要的:
Might be you had failed to put your first frame in the EDT too, do watch the code, is this what you actually want :