Java - 显示最小化的 JFrame 窗口 [英] Java - Show a minimized JFrame window

查看:36
本文介绍了Java - 显示最小化的 JFrame 窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果一个 JFrame 窗口被最小化了,有什么方法可以让它回到焦点?

If a JFrame window is minimized, is there any way to bring it back to focus?

我试图让它点击某个点,然后恢复它.

I am trying to get it to click a certain point, then restore it.

            while (isRunning) {
                start = System.currentTimeMillis();
                frame.setState(Frame.ICONIFIED);
                robot.mouseMove(clickX, clickY);
                robot.mousePress(InputEvent.BUTTON1_MASK);
                frame.setState(Frame.NORMAL);
                Thread.sleep(clickMs - (System.currentTimeMillis() - start));
            }

推荐答案

如果你想把它从iconified中恢复过来,你可以把它的状态设置为normal:

If you want to bring it back from being iconified, you can just set its state to normal:

JFrame frame = new JFrame(...);
// Show the frame
frame.setVisible(true);

// Sleep for 5 seconds, then minimize
Thread.sleep(5000);
frame.setState(java.awt.Frame.ICONIFIED);

// Sleep for 5 seconds, then restore
Thread.sleep(5000);
frame.setState(java.awt.Frame.NORMAL);

示例来自这里.

还有WindowEvents 每当状态改变时触发,而 WindowListener 接口处理这些触发器.在这种情况下,您可以使用:

There are also WindowEvents that are triggered whenever the state is changed and a WindowListener interface that handles these triggers.In this case, you might use:

public class YourClass implements WindowListener {
  ...
  public void windowDeiconified(WindowEvent e) {
    // Do something when the window is restored
  }
}

如果你想检查另一个程序的状态变化,没有纯Java"的解决方案,只需要获取窗口的ID.

If you are wanting to check another program's state change, there isn't a "pure Java" solution, but just requires getting the window's ID.

这篇关于Java - 显示最小化的 JFrame 窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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