且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

带有双显示器的Java全屏jframe

更新时间:2022-06-06 23:37:53

所以这里我自己的问题,我最终使用的解决方法,我认为唯一不那么难看的解决方法我可以找到使用此代码

So here my own anwser to my own problem, the workaround I finally use and I think is the only not so ugly workaround I can found is to use this code

private void jmiFullscreenActionPerformed(java.awt.event.ActionEvent evt) {                                              
     GraphicsDevice gd = this.gameFrame.getGraphicsConfiguration().getDevice();

    if (!this.gameFrame.isResizable() ) {
        //gd.setFullScreenWindow(null);
        this.gameFrame.setResizable(true);
        this.gameFrame.setPreferredSize(new Dimension(400, 300));
    } else {
        this.gameFrame.setResizable(false);
        this.gameFrame.setPreferredSize(new Dimension(gd.getDefaultConfiguration().getBounds().getSize()));
        this.gameFrame.setExtendedState(Frame.MAXIMIZED_BOTH);
    }
    refresh();
}           

而不是我原来的例子中的这个

instead of this in my original example

private void jmiFullscreenActionPerformed(java.awt.event.ActionEvent evt) {
    GraphicsDevice gd = this.gameFrame.getGraphicsConfiguration().getDevice();

    if (gd.getFullScreenWindow() != null) {
        gd.setFullScreenWindow(null);
        this.gameFrame.setResizable(true);
        this.gameFrame.setPreferredSize(new Dimension(400, 300));
    } else {
        this.gameFrame.setResizable(false);
        this.gameFrame.setPreferredSize(new Dimension(gd.getDefaultConfiguration().getBounds().getSize()));
        this.gameFrame.enableInputMethods(false);
        gd.setFullScreenWindow(this.gameFrame);
    }
    refresh();
}

所以最后我没有使用java全屏功能而我只是使用了一些我的jframe的属性使它看起来像一个全屏框架。

So finally I'm not using the java fullscreen function and I just use some properties of my jframe to make it look like a fullscreen frame.

希望它对你们有些帮助!
有一个美好的一天

Hope it help some of you !! have a nice day