-
Bug
-
Resolution: Unresolved
-
P4
-
8u40
-
java version "1.8.0_40-ea"
Java(TM) SE Runtime Environment (build 1.8.0_40-ea-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.40-b13, mixed mode)
In an app that I am working on, running on a dual monitor setup, I notice that the main window can switch from one screen to the other when minimized and maximized (at least on Windows 7). I reduced this to the following minimal test case (read the comments in the code for instructions):
import javafx.application.Application;
import javafx.collections.ObservableList;
import javafx.geometry.Rectangle2D;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.BorderPane;
import javafx.stage.Screen;
import javafx.stage.Stage;
/**
* This is a minimal test app for an issue I am seeing in a much larger application that I am working on
* related to a dual monitor setup.
*
* This program reproduces an issue for me on Windows 7, and JDK 8u40 b09. Run the program and the app window
* should be maximised on the *secondary* screen. Click the icon in the Windows taskbar to minimise the app,
* then click again to maximise. The app is now maximised but has switched to the primary screen.
*
* Note the line stage.setMaximized(true) - if you comment this out, the issue goes away.
*/
public class DualMonitorTest extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) {
stage.setTitle("Dual Monitor Test");
stage.setResizable(true);
stage.setMaximized(true); // comment out this line and there is no issue
BorderPane bp = new BorderPane();
bp.setCenter(new Button("Imagine that clicking this button gives pay increases to the JavaFX team ... in fact, it does nothing."));
Scene scene = new Scene(bp);
stage.setScene(scene);
stage.show();
ObservableList<Screen> screens = Screen.getScreens();
Rectangle2D bounds = screens.get(1).getVisualBounds();
stage.setX(bounds.getMinX());
stage.setY(bounds.getMinY());
stage.setWidth(bounds.getWidth());
stage.setHeight(bounds.getHeight());
}
}
import javafx.application.Application;
import javafx.collections.ObservableList;
import javafx.geometry.Rectangle2D;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.BorderPane;
import javafx.stage.Screen;
import javafx.stage.Stage;
/**
* This is a minimal test app for an issue I am seeing in a much larger application that I am working on
* related to a dual monitor setup.
*
* This program reproduces an issue for me on Windows 7, and JDK 8u40 b09. Run the program and the app window
* should be maximised on the *secondary* screen. Click the icon in the Windows taskbar to minimise the app,
* then click again to maximise. The app is now maximised but has switched to the primary screen.
*
* Note the line stage.setMaximized(true) - if you comment this out, the issue goes away.
*/
public class DualMonitorTest extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) {
stage.setTitle("Dual Monitor Test");
stage.setResizable(true);
stage.setMaximized(true); // comment out this line and there is no issue
BorderPane bp = new BorderPane();
bp.setCenter(new Button("Imagine that clicking this button gives pay increases to the JavaFX team ... in fact, it does nothing."));
Scene scene = new Scene(bp);
stage.setScene(scene);
stage.show();
ObservableList<Screen> screens = Screen.getScreens();
Rectangle2D bounds = screens.get(1).getVisualBounds();
stage.setX(bounds.getMinX());
stage.setY(bounds.getMinY());
stage.setWidth(bounds.getWidth());
stage.setHeight(bounds.getHeight());
}
}