Hi,
I'm trying to display a modal dialog frame (JDialog)
on top of a fullscreen window. My current status is that it works when I run the application from eclipse. However it doesn't, when I run it from the windows command line. Java arguments are the same. (???? Can anyone please explain the difference between eclipse and command line java to me, please?)
What I have is:
public class ETGui extends JFrame {
private boolean isFullScreen = false;
private GraphicsDevice device;
public ETGui(GraphicsDevice device) { // device is set externally: GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()[0]
super(device.getDefaultConfiguration());
this.device = device;
setDefaultCloseOperation(EXIT_ON_CLOSE);
addWindowListener(new MyWindowListener());
}
private boolean iAmEnabled = true; // if window should be "enabled" = reacting to alt + tab
public boolean isIAmEnabled() {
return iAmEnabled;
}
public void setIAmEnabled(boolean b) {
iAmEnabled = b;
}
//window listener
private final class MyWindowListener extends WindowAdapter {
public void windowActivated(WindowEvent e) {
changeScreen(true);
}
public void windowDeactivated(WindowEvent e) {
if (isIAmEnabled()) { //unfaded - go to windowed mode only if window is made enabled
changeScreen(false);
} else { //faded
changeScreen(true); //make window fullscreen!
}
}
}
public void changeScreen(boolean full) {
if (full) {
// Full-screen mode
if (isFullScreen) { //do only, if full screen is supported. otherwise there is a windowed frame, so trying to set fullscreen yields strange results
device.setFullScreenWindow(this);
validate();
toFront();
}
} else {
// Windowed mode
if (isFullScreen){
device.setFullScreenWindow(null);
validate();
}
}
}
public void begin() { //called externally when window is instatiated
isFullScreen = device.isFullScreenSupported();
setUndecorated(isFullScreen);
setResizable(!isFullScreen);
if (isFullScreen) {
// Full-screen mode
device.setFullScreenWindow(this);
validate();
} else {
// Windowed mode
pack();
setVisible(true);
}
}
}
the changeSreen() Method should let the fullscreen window respond to alt+tab events, i.e. hide the window. But it should only be deactivated, if no modal dialog is visible. So I bring up dialogs like this:
frame.setIAmEnabled(false);
// show the dialog with input fields
frame.setIAmEnabled(true);
When the dialog comes up, it is indeed on top of the frame. However, Windows minimizes the fullscreen window so the whole program has to be brought to front manually!
Is there a problem with my code?
Or is there a better solution to show JFrames on top of a full screen window while it is possible to use Alt-Tab to switch windows?
I'm really stuck here. Especially, because there are no problems in Eclipse.
Thanks a lot,
Nini