JDialog框未获得焦点 [英] JDialog box not gaining focus

查看:82
本文介绍了JDialog框未获得焦点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在生成一个无模式对话框,提示用户打开一个新窗口.可以通过两种方式打开该框,直接从我正在编写的框架的文件菜单中打开,或者通过面板插入的框架间接地打开该框.

I have a modeless dialog box being generated which prompts users to open a new window. The box can be opened in two ways, either directly from the file menu for the frame I'm writing or indirectly via the framework my panel is plugging into.

当我直接通过文件菜单拨打电话时,对话框将完全按照我的意愿显示焦点.但是,当我间接打开框架时,它没有应有的焦点.

When I make the call directly via the file menu the dialog box comes up with focus exactly as I want. But when I have the framework indirectly open the dialog box it does not have focus as it should.

打开对话框的两种方法似乎没有什么区别,在两种情况下都调用了load函数,直到打开对话框的5种方法都没有.在这两种情况下,生成对话框的框架都是在生成对话框时实现的.在使对话框可见后,我尝试调用requestFocus,但似乎没有任何作用.

There doesn't seem to be a difference between the two methods of opening the dialog, in both cases a load function is called and it's not until 5 method calls later the dialog box is opened. In both cases the frame which generates the dialog box is realized at the time the box is generated. I've tried calling requestFocus after making the dialog box visible but it doesn't seem to do anything.

有人建议为什么对话框没有焦点,或者如何将其作为与通常具有焦点的窗口分开的窗口作为焦点?

Any suggestion why the dialog box wouldn't have focus, or how I can give it focus as a separate window from the window that usually has focus?

推荐答案

创建对话框时,请尝试将主GUI设置为对话框的父级.

When you create the dialog, try setting the main GUI as parent of the dialog.

在第一种情况下,当您从菜单中单击时,它将自动将主GUI设置为对话框的父级,但是在第二种情况下则没有.

In the first case, when you click from menu, it automatically sets the main GUI as the parent of the dialog, but it doesnt in the second case.

因此,请确保在创建对话框时将主GUI/窗口始终设置为父级.

So make sure when you create the dialog, you are setting the main GUI/ window as parent always.

大多数情况下应该有帮助.

It should help most times.

这篇关于JDialog框未获得焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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