我正在尝试使用 GlassPane 将图标闪烁给用户。我正在运行一个javax.swing.Timer
基本上执行此操作的:
for (int i = 0; i < 3; i++) {
frame.getGlassPane().setVisible(true);
try {
Thread.sleep(500);
} catch (InterruptedException e1) {
//To change body of catch statement use File | Settings | File Templates.
e1.printStackTrace();
}
frame.getGlassPane().setVisible(false);
}
不幸的是,如果我让 EDT(计时器内的当前线程)休眠,则图标不会显示,因为该paintComponent
方法在线程进入休眠状态之前无法完全调用。因此,当下一条指令启动时,玻璃窗格被隐藏,因此图标永远不会显示。有没有办法使用这种(类似的)方法来实现我想要的?