Javafx setMaximized on OSX

时间:2015-05-05 09:46:33

标签: eclipse macos javafx

我在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);
    }
}

值得注意的是,我发现从这里尝试进入实际的全屏模式会完全崩溃Java。

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动画方面表现不佳。

1 个答案:

答案 0 :(得分:1)

我不知道为什么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);