JOptionPane不会在其他窗口的顶部显示其对话框 [英] JOptionPane won't show its dialog on top of other windows

查看:159
本文介绍了JOptionPane不会在其他窗口的顶部显示其对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在摆动提醒应用程序方面存在问题,该应用程序可以最小化到托盘关闭。我的问题在于,我需要按照我设置的方式按时弹出JOptionPane对话框,但问题是,当我最小化它时,对话框会弹出,但不会出现在windows的顶部,当其他应用程序如explorer,firefox正在运行,任何人都知道如何在Windows上弹出对话框,无论正在运行什么应用程序?

I have problem currently for my swing reminder application, which able to minimize to tray on close. My problem here is, I need JOptionPane dialog to pop up on time according to what I set, but problem here is, when I minimize it, the dialog will pop up, but not in the top of windows when other application like explorer, firefox is running, anyone know how to pop up the dialog box on top of windows no matter what application is running?

推荐答案

创建一个分别为空虚拟JFrame,将其设置在顶部并将其用作JOptionPane的组件而不是null。因此,JOptionPane始终位于应用程序的所有其他窗口的顶部。您还可以使用虚拟JFrame的位置确定JOptionPane在屏幕上的显示位置。

Create an empty respectively dummy JFrame, set it always on top and use it as the component for the JOptionPane instead of null. So the JOptionPane remains always on top over all other windows of an application. You can also determine where the JOptionPane appears on screen with the location of the dummy JFrame.

JFrame frmOpt;  //dummy JFrame

private void question() {
    if (frmOpt == null) {
        frmOpt = new JFrame();
    }
    frmOpt.setVisible(true);
    frmOpt.setLocation(100, 100);
    frmOpt.setAlwaysOnTop(true);
    String[] options = {"delete", "hide", "break"};
    int response = JOptionPane.showOptionDialog(frmOpt, msg, title, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, "delete");
    if (response == JOptionPane.YES_OPTION) {
        removeRow();
    }
    frmOpt.dispose();
}

这篇关于JOptionPane不会在其他窗口的顶部显示其对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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