简体   繁体   中英

Making JFrame fullscreen in Ubuntu/Unity

In Ubuntu (actually in unity), I can't make swing's JFrame's fullscreen. I've tried lots of ways written in stackoverflow but noone of them worked for me.

I'm trying to develop a game and I need to see nothing but my game on my screen. However, ubuntu forces me to display Unity Launcher and the menubar(Clock, wifi icon, etc..) above.

How can I run my Java programs in fullscreen mode? Here's my code:

import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;

import javax.swing.JFrame;

public class Starter extends JFrame {
    private static final long serialVersionUID = -2656706278597877008L;

    public static void main(String[] args) {
        new Starter();
    }

    public Starter() {
        super(UIConstants.FRAME_TITLE);
        setResizable(false);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setUndecorated(true);
        makeFullScreen();
        setVisible(true);
    }

    private void makeFullScreen() {
        GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice device = env.getDefaultScreenDevice();
        device.setFullScreenWindow(this);
    }
}

And this program is seen as follows: 程序输出

您不能删除全局菜单或在其上方放置一个窗口,只需简单地将主题更改为另一个主题即可:lxde

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM