7
votes

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);
}
4
What does vc.isFullScreenSupported() return?Adam
Maybe try it on another OS and then update your question?JMK
I ran your code on Windows 7 and the same phenomenon appeared -- Window the full size of the screen, with title bar. I think this is the expected behavior.Roddy of the Frozen Peas
Try setting window.setUndecorated(true); instead of false.Gilberto Torrezan
@Adam It returns true, so it should work.Jon

4 Answers

4
votes

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.

3
votes

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);
    }
}
1
votes

This thread is very old but still comes in ACTUAL search results but with wrong answers. So i'll post actual the real solution.

Swing full screen will be set with the setExtendedState() function, not with the setFullScreenWindow() function!

JFrame myFrame = new JFrame();
....
myFrame.setExtendedState(MAXIMIZED_BOTH);

Then u'll have a decorated full screen window, with all buttons and a correct toolbar optic and it works fine with Ubuntu and any other OS.

0
votes

Though this might in most cases not be applicable I'd like to share my solution to this problem.

In my case, I frequently need to develop Java/Scala apps for our university institution (psychological tests). To circumpass this issue we decided to install sawfish on our experimental pc's.

If this solution is applicable to your needs you can install (an extremely outdated) sawfish through Ubuntu facilities (Software Center, Aptitute, apt-get) or - what I'd prefer - install or compile an up-to-date sawfish manually.

Other window and/or desktop managers might give similar functionality, but we experienced artifacts when we tried XFCE or LXDE with disabled/deleted panels.