问题描述
||
我最初在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并填写错误报告。
问候,
斯特凡