如何解决图标化的JFrame显示在win 7任务栏上的模态JDialog后面,单击
|| 我最初在Win XP上开发了以下代码。当您单击XP任务栏中的程序图标时,父框架保持图标化,并且JDialog返回焦点,这是我想要的行为。但是,当在Win 7上单击程序的任务栏图标时,父JFrame会将其状态更改回“正常”并显示在应用程序模式JDialog的后面。我尝试重写JFrame的setExtendedState()方法来拦截框架的状态变化,但是没有运气。 是否有解决方法,还是我需要解决的逻辑缺陷?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并填写错误报告。
问候,
斯特凡
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。