如何使 JFrame 真正全屏?

2022-01-24 00:00:00 fullscreen java swing jframe

在我的 Java 应用程序中,我尝试使用以下代码使 JFrame 真正全屏显示:

In my Java application I try to make a JFrame really fullscreen by using this code:

public class MainFrame extends JFrame {

    private static final long serialVersionUID = 1L;

    public MainFrame() {
        super();
        this.setTitle();
        this.setUndecorated(true);

        this.setExtendedState(JFrame.MAXIMIZED_BOTH);

        this.setVisible(true);
        //this.pack();
    }
}

但在我的 Mac 上,我仍然可以看到 Dock 和 OSX 的顶部工具栏.那么如何创建一个真正占用整个屏幕的 JFrame?

But on my Mac I can still see the Dock and the top toolbar of the OSX. So how can I create a JFrame that really consumes my whole screen?

编辑我必须补充一点,我想从 Eclipse 插件中调用该 JFrame.

EDIT I have to add that I want to call that JFrame from a eclipse plugin.

推荐答案

我还没试过,但是Java有全屏API,应该可以满足你的需求:

I haven't tried it yet, but Java has fullscreen API, which should meet your needs:

http://docs.oracle.com/javase/tutorial/额外/全屏/index.html

相关文章