Java Fullscreen mode not working on Ubuntu

后端 未结 4 649
渐次进展
渐次进展 2020-12-10 16:30

So I\'m using Ubuntu and when I want to enter fullscreen mode in Java, a normal window appears with max screen size, instead of a fullscreen window without title bar etc. I

4条回答
  •  时光取名叫无心
    2020-12-10 16:47

    On win7, with this code (I set the undecorated flag to true as suggested by @Gilberto and added a RED panel) it seems to work OK. If it does not work on Ubuntu, then it may mean that FullScreen mode is unsupported:

    import java.awt.Color;
    import java.awt.GraphicsDevice;
    import java.awt.GraphicsEnvironment;
    
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    
    public class Main {
        public static void main(String[] args) {
            GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
            GraphicsDevice vc = env.getDefaultScreenDevice();
            JFrame window = new JFrame();
            JPanel comp = new JPanel();
            comp.setBackground(Color.RED);
            window.add(comp);
            window.setUndecorated(true);
            window.setResizable(false);
            vc.setFullScreenWindow(window);
        }
    }
    

提交回复
热议问题