[英]How can I show a String for only a few seconds in Java?
I would like to show a String for only 5 secs on the center of my JFrame. 我只想在JFrame的中心显示一个String,持续5秒钟。 How can I do it?
我该怎么做?
JLabel
to your JFrame
. JLabel
添加到您的JFrame
。 JLabel
. JLabel
的文本。 JLabel
to the empty string or remove it entirely. JLabel
的文本设置为空字符串或将其完全删除。 This is a Swing question and so the solution is to use a Swing Timer not Thread.sleep(...)
. 这是一个Swing问题,因此解决方案是使用Swing计时器而不是
Thread.sleep(...)
。 If you use thread sleep, you will risk sleeping the Swing event thread, putting the entire GUI to sleep, preventing any new text from showing. 如果使用线程睡眠,则有冒险将Swing事件线程睡眠,使整个GUI进入睡眠状态,从而阻止显示任何新文本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.