Java Fullscreen mode not working on Ubuntu

血红的双手。 提交于 2019-11-28 11:20:21
Trilarion

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.

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

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!