本文是小编为大家收集整理的关于如何将JavaFX舞台/框架设置为最大化?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。
问题描述
我正在使用Javafx2.我希望我的框架最大化,但我没有看到任何方法.我在Internet上搜索了一些,但没有成功.对于舞台,我看到setFullScreen()和setIconified(),但我看不到setMaximized().
推荐答案
评估javafx 2.0 SDK样品提供的集合的源代码时,实现窗口最大化的当前有效方法是
Screen screen = Screen.getPrimary(); Rectangle2D bounds = screen.getVisualBounds(); primaryStage.setX(bounds.getMinX()); primaryStage.setY(bounds.getMinY()); primaryStage.setWidth(bounds.getWidth()); primaryStage.setHeight(bounds.getHeight());
(您在windowbuttons.java中找到类似的代码)
仍然启用"最大化"按钮,并且在单击它时,窗口会增加一些(Windows OS).之后,禁用了"最大化"按钮.在提供的示例中,标准按钮更换.也许这仍然是一个问题.
其他推荐答案
Java 8的舞台类实现提供了最大化的属性,可以设置为:
primaryStage.setMaximized(true);
其他推荐答案
更好地使用多屏幕兼容最大化逻辑:
// Get current screen of the stage ObservableList<Screen> screens = Screen.getScreensForRectangle(new Rectangle2D(stage.getX(), stage.getY(), stage.getWidth(), stage.getHeight())); // Change stage properties Rectangle2D bounds = screens.get(0).getVisualBounds(); stage.setX(bounds.getMinX()); stage.setY(bounds.getMinY()); stage.setWidth(bounds.getWidth()); stage.setHeight(bounds.getHeight());
问题描述
I'm using JavaFX 2. I want my frame to open maximized but I'm not seeing a way. I searched a bit on the internet without success. For the stage I see setFullScreen() and setIconified() but I don't see anything like setMaximized().
推荐答案
When evaluating the sourcecode of the Ensemble.jar provided with the samples of JavaFX 2.0 SDK, the currently valid way to achieve window maximizing is
Screen screen = Screen.getPrimary(); Rectangle2D bounds = screen.getVisualBounds(); primaryStage.setX(bounds.getMinX()); primaryStage.setY(bounds.getMinY()); primaryStage.setWidth(bounds.getWidth()); primaryStage.setHeight(bounds.getHeight());
(you find similar code in WindowButtons.java)
The 'maximize' button is still enabled and when clicking it, the windows will grow a bit more (Windows OS). After this the 'maximize 'button is disabled. In the provided example the standard buttons are replaced. Maybe this is still an issue.
其他推荐答案
The Java 8 implementation of the Stage class provides a maximized property, which can be set as follows:
primaryStage.setMaximized(true);
其他推荐答案
Better use Multi-Screen compatible maximize logic:
// Get current screen of the stage ObservableList<Screen> screens = Screen.getScreensForRectangle(new Rectangle2D(stage.getX(), stage.getY(), stage.getWidth(), stage.getHeight())); // Change stage properties Rectangle2D bounds = screens.get(0).getVisualBounds(); stage.setX(bounds.getMinX()); stage.setY(bounds.getMinY()); stage.setWidth(bounds.getWidth()); stage.setHeight(bounds.getHeight());