Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Fullscreen mode not working on Ubuntu

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 admit, I'm not even sure what the fullscreen mode should look like in Java, because I have not tried it on any other OS. But I assume it should be a screen without title bar. Anyone else who has this problem?

This is the code I use. ; pretty straight forward.

public static void main(String[] args) {
    GraphicsEnvironment env = GraphicsEnvironment
            .getLocalGraphicsEnvironment();
    GraphicsDevice vc = env.getDefaultScreenDevice();
    JFrame window = new JFrame();
    window.setUndecorated(false);
    window.setResizable(false);
    vc.setFullScreenWindow(window);
}
like image 349
Jon Avatar asked Sep 20 '12 20:09

Jon


2 Answers

On Ubuntu (probably other Linux distros as well) it doesn't work. Full screen mode in Java doesn't cover the full screen. It leaves the toolbars out. Always, whatever you do.

I tried the two examples above and the examples from the official FSEM tutorial and some application I know are using Java/Swing and Full screen mode (FreeCol and TripleX) and noone was able to cover the task/toolbar areas of the screen.

My configuration is Ubuntu 12.10 with either OpenJDK or SUN-JRE 1.7.0_09 and either Unity or Gnome. Interestingly the java call to isFullScreenSupported() returns true. So, while the Java JRE says it supports full screen exclusive, it doesn't.

Some possible explanations might be given in another question.

like image 89
Trilarion Avatar answered Oct 06 '22 05:10

Trilarion


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);
    }
}
like image 39
Guillaume Polet Avatar answered Oct 06 '22 04:10

Guillaume Polet