我在OSX上的setMaximized()方法
当我调用它时:
Scene scene = new Scene(debug);
stage.setOnCloseRequest(event -> System.exit(0));
stage.setScene(scene);
stage.setMaximized(true);
stage.show();
应用程序窗口消失。为了澄清,我试图从OSX 10.9.5上的Eclipse运行该应用程序。同样的逻辑似乎在Windows上正常工作。是否有可能引起这一点的已知问题?我真的不想去编写窗口的特定实现平台。
编辑:这是整个类:
public class Main extends Application {
/** Pane that is used for outputting debug information about touch interactions and user interface elements. */
private DebugParent debug;
private Control customPane;
private Stage stage;
@Override
public void start(Stage stage) throws Exception {
Font.loadFont(this.getClass().getResourceAsStream("/ui/fonts/titillium.otf"), 20);
customPane = FXMLLoader.load(this.getClass().getResource("/ui/Main.fxml"), null, new CustomBuilderFactory());
customPane.dragProcessingModeProperty().set(EventProcessingMode.HANDLER);
// Init Debug
debug = new DebugParent(customPane);
debug.registerCustomPane(customPane);
debug.setOverlayVisible(false);
// Init menu
ContextMenu menu = new MainMenu(catalog, customPane);
customPane.setContextMenu(menu);
// Init scene
Scene scene = new Scene(debug);
this.stage = stage;
this.stage.setOnCloseRequest(event -> System.exit(0));
this.stage.setScene(scene);
this.stage.setMaximized(true);
this.stage.show();
this.stage.addEventHandler(KeyEvent.KEY_PRESSED, this::handleKey);
// Invalidate
customPane.invalidate();
customPane.requestFocus();
}
private void handleKey(KeyEvent keyEvent) {
switch (keyEvent.getCode()) {
case F10: stage.setMaximized(!stage.isMaximized()); break;
case F11: stage.setFullScreen(!stage.isFullScreen()); break;
}
}
public static void main(String[] args) {
launch(args);
}
}
值得注意的是,我发现尝试从这里输入实际的全屏模式完全崩溃了。
2015-05-06 21:33:14.795 java[9119:507] *** Assertion failure in -[_NSWindowFullScreenTransition makeAndSetupOverlayWindow], /SourceCache/AppKit/AppKit-1265.21/AppKit.subproj/NSWindowFullScreenTransition.m:776
2015-05-06 21:33:14.799 java[9119:507] An uncaught exception was raised
2015-05-06 21:33:14.799 java[9119:507] Invalid parameter not satisfying: _transitionedWindowBeforeContents != nil
2015-05-06 21:33:14.799 java[9119:507] (
0 CoreFoundation 0x00007fff909e125c __exceptionPreprocess + 172
1 libobjc.A.dylib 0x00007fff93d6be75 objc_exception_throw + 43
2 CoreFoundation 0x00007fff909e1038 +[NSException raise:format:arguments:] + 104
3 Foundation 0x00007fff949f43d1 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 189
4 AppKit 0x00007fff91425068 -[_NSFullScreenTransition makeAndSetupOverlayWindow] + 267
5 AppKit 0x00007fff90e4f060 -[_NSFullScreenTransition enterFullScreenTransitionWithOptions:animated:activatingIt:] + 933
6 AppKit 0x00007fff90e4e48e -[NSWindow _enterFullScreenMode:animating:activating:] + 291
7 libglass.dylib 0x00000001204d0c99 -[GlassViewDelegate enterFullscreenWithAnimate:withKeepRatio:withHideCursor:] + 153
8 libglass.dylib 0x00000001204cc606 Java_com_sun_glass_ui_mac_MacView__1enterFullscreen + 358
9 ??? 0x0000000109281954 0x0 + 4448590164
10 ??? 0x0000000109273420 0x0 + 4448531488
11 ??? 0x0000000109273420 0x0 + 4448531488
12 ??? 0x0000000109273c4d 0x0 + 4448533581
)
2015-05-06 21:33:14.800 java[9119:507] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: _transitionedWindowBeforeContents != nil'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff909e125c __exceptionPreprocess + 172
1 libobjc.A.dylib 0x00007fff93d6be75 objc_exception_throw + 43
2 CoreFoundation 0x00007fff909e1038 +[NSException raise:format:arguments:] + 104
3 Foundation 0x00007fff949f43d1 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 189
4 AppKit 0x00007fff91425068 -[_NSFullScreenTransition makeAndSetupOverlayWindow] + 267
5 AppKit 0x00007fff90e4f060 -[_NSFullScreenTransition enterFullScreenTransitionWithOptions:animated:activatingIt:] + 933
6 AppKit 0x00007fff90e4e48e -[NSWindow _enterFullScreenMode:animating:activating:] + 291
7 libglass.dylib 0x00000001204d0c99 -[GlassViewDelegate enterFullscreenWithAnimate:withKeepRatio:withHideCursor:] + 153
8 libglass.dylib 0x00000001204cc606 Java_com_sun_glass_ui_mac_MacView__1enterFullscreen + 358
9 ??? 0x0000000109281954 0x0 + 4448590164
10 ??? 0x0000000109273420 0x0 + 4448531488
11 ??? 0x0000000109273420 0x0 + 4448531488
12 ??? 0x0000000109273c4d 0x0 + 4448533581
)
libc++abi.dylib: terminating with uncaught exception of type NSException
从外观上看,Javafx对OSX动画的效果不佳。
我不知道为什么setMaximized()在OS X上不起作用,但是这是有关该工作的一些工作:您可以尝试获取VisualBounds宽度和高度并使用它。
Scene scene = stage.getScene();
Screen primaryScreen = Screen.getPrimary();
Rectangle2D visualBounds = primaryScreen.getVisualBounds();
double width = visualBounds.getWidth();
double height = visualBounds.getHeight();
scene = new Scene(root, width, height);