无模式JDialog不显示内容 [英] Modeless JDialog not showing contents

查看:163
本文介绍了无模式JDialog不显示内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(Java SE 6) 我正在尝试创建一个弹出对话框,该对话框在程序执行一些耗时的工作时显示请稍候"消息.为此,我选择使用无模式的JDialog,以便程序在JDialog可见时继续运行并运行(如果您使用的是模式对话框,则程序将停止运行,直到用户关闭对话框为止).

(Java SE 6) I'm trying to create a pop-up dialog that displays a "please wait" message while my program does some time-intensive work. To do this, I've chosen to use a modeless JDialog, so that the program continues to run and does work while the JDialog is visible (if you use a modal one, the program will halt until the dialog is closed by the user).

问题是,当您以这种方式使用无模式对话框时,会显示带有标题的JDialog,但是内容却没有(我猜它们由于某种原因没有被绘制).我试过打电话给repaint等,但似乎没有任何效果.

The problem is that when you use a modeless dialog in this fashion the JDialog with a title appears, but the contents don't (I'm guessing they don't get painted for some reason). I've tried calling repaint etc but nothing seems to work.

现在,根据互联网上的一堆人的说法,这是Swing的一个真正的错误,我发现的唯一答案是不以这种方式执行操作,并找到其他一些通知用户等待的方法.我很好奇这里是否有人以前曾遇到过此问题,并已找到解决方法.

Now, according to a bunch of people on the interwebs this is a genuine bug with Swing, and the only answers I've found are to not do things this way and find some other means of notifying the user to wait. I'm curious if anyone here has had this issue before and has figured out a work-around.

谢谢!

推荐答案

作为替代方案,请考虑使用示例中所建议

As an alternative, consider using SwingWorker and showing interim progress, as suggested in this example.

这篇关于无模式JDialog不显示内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆