Stage.Min/MaxWidth/Height don't scale
Chris Nahr
chris.nahr at gmail.com
Wed Nov 18 12:24:44 UTC 2015
On Windows the minimum & maximum size properties of Stage don't scale to
the current DPI settings, unlike all other drawing coordinates. The
explicit size properties (setWidth/setHeight) do scale but setMinWidth,
setMaxWidth, setMinHeight & setMaxHeight were apparently overlooked. Any
values passed to them are interpreted as unscaled pixels.
Below I've added a short sample program to demonstrate the issue.
Minimum size should just cover the drawn rectangle plus margins, and
maximum size should be twice as big. But running at 200% DPI the
*maximum* size will just cover the rectangle whereas the minimum size
will show only a fraction of the rectangle.
(I'd file a bug report but my JIRA account didn't transition to the new
bug tracking system, probably because I'm not an OpenJDK contributor.)
-- Chris
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
public class StageSizeTest extends Application {
@Override
public void start(Stage primaryStage) {
// draw scene-filling rectangle with margin
final int margin = 10, size = 200;
Rectangle rect = new Rectangle(margin, margin, size, size);
StackPane root = new StackPane(rect);
final int sceneSize = size + 2 * margin;
Scene scene = new Scene(root, sceneSize, sceneSize);
// add extra margin for non-client area
final int stageSize = sceneSize + 3 * margin;
primaryStage.setMinWidth(stageSize);
primaryStage.setMinHeight(stageSize);
primaryStage.setMaxWidth(2 * stageSize);
primaryStage.setMaxHeight(2 * stageSize);
primaryStage.setTitle("Stage Size Test");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
More information about the openjfx-dev
mailing list