[英]Iconified JFrame showing behind modal JDialog on win 7 taskbar click
我最初在 Win XP 上开发了以下代码。 当您单击 XP 任务栏中的程序图标时,父框架保持图标化,JDialog 返回焦点,这是我想要的行为。 但是,当在 Win 7 上单击程序的任务栏图标时,父 JFrame 将其 state 更改回正常并显示在应用程序模式 JDialog 后面。 我尝试覆盖 JFrame 的 setExtendedState() 方法来拦截框架的 state 更改,但没有成功。
是否有解决方法,或者我的逻辑是否存在我需要解决的缺陷?
import java.awt.*;
import javax.swing.JDialog;
import javax.swing.JFrame;
public class TestLogin extends JFrame {
public TestLogin() {
this.setSize(300, 300);
iconify(this);
setLocationRelativeTo(null);
this.setTitle("I'm a Frame!");
this.setVisible(true);
LoginScreen login = new LoginScreen(this);
}
public static void main(String [] args) {
TestLogin frame = new TestLogin();
}
public static void iconify(Frame frame) {
int state = frame.getExtendedState();
// Set the iconified bit
state |= Frame.ICONIFIED;
// Iconify the frame
frame.setExtendedState(state);
}
public static void deiconify(Frame frame) {
int state = frame.getExtendedState();
// Clear the iconified bit
state &= ~Frame.ICONIFIED;
// Deiconify the frame
frame.setExtendedState(state);
}
public class LoginScreen extends JDialog {
private JFrame root;
public LoginScreen(JFrame root) {
super(root);
this.root = root;
setLocationRelativeTo(null);
this.setTitle("I'm a Dialog!");
setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
this.setSize(200, 200);
setVisible(true);
}
}
}
它看起来像是“一次编写,随处运行”的 java 范例中的一个错误。 如果这包括 windows 7,那么您可以联系 oracle 并填写错误报告。
问候, 斯蒂芬
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.