JDialogBox 不间歇地显示内容
晚上好,stackoverflow。 我有一个涉及 JOptionPanes 的问题。 他们经常不显示我提供的内容。 在这里说明我的问题: 它应该是这样的:
每隔一段时间,它就会显示如下内容:
这里是构建该东西的函数调用。 “panel”只是一个添加了小部件的简单 JPanel。
int a = JOptionPane.showConfirmDialog(null,panel,"Please enter result details",JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE);
让我发疯的是它是间歇性的,所以我不知道是什么原因造成的。 有什么想法吗?
Good evening stackoverflow.
I have a problem involving JOptionPanes.
Every so often they simply do not display the content that i give it.
And here to illustrate my problem:
This is what it should look like:
and every so often, this is what it displays:
heres the function call to build the thing. "panel" is just a simple JPanel with the widgets added.
int a = JOptionPane.showConfirmDialog(null,panel,"Please enter result details",JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE);
The thing with this that is driving me crazy is that it's intermittent so i have no idea what caused this.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该确保在事件调度线程上调用 JOptionPane 更新代码。 Swing 组件应在 EDT 上更新,以确保它们正确重绘,大多数不正确更新的问题是因为没有在 EDT 上调用它。
如果您不确定自己是否处于 EDT,SwingUtilities.isEventDispatchThread() 是一个很好的调试工具。
编辑:我错过了有一条评论提到了这一点,抱歉。
You should ensure that you are calling your JOptionPane updating code on the Event Dispatching Thread. Swing components should be updated on the EDT to ensure they are repainted properly, most issues with incorrect updating are because it is not being called on the EDT.
If you are ever unsure about whether or not you are on the EDT, SwingUtilities.isEventDispatchThread() is a good debugging tool.
Edit: I missed that there was a comment that mentioned this, sorry.