简体   繁体   English

Java全屏模式在Ubuntu上不起作用

[英]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. 所以我正在使用Ubuntu,当我想以Java进入全屏模式时,会出现一个具有最大屏幕尺寸的普通窗口,而不是没有标题栏等的全屏窗口。我承认,我什至不确定全屏模式应该是什么看起来像Java,因为我没有在其他任何操作系统上尝试过。 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);
}

On Ubuntu (probably other Linux distros as well) it doesn't work. 在Ubuntu(可能还有其他Linux发行版)上,它不起作用。 Full screen mode in Java doesn't cover the full screen. Java中的全屏模式不能覆盖全屏。 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. 我尝试了上面的两个示例以及来自FSEM官方教程的示例,并且我知道某些应用程序正在使用Java / Swing和全屏模式(FreeCol和TripleX),但是没有人能够覆盖屏幕的任务/工具栏区域。

My configuration is Ubuntu 12.10 with either OpenJDK or SUN-JRE 1.7.0_09 and either Unity or Gnome. 我的配置是带有OpenJDK或SUN-JRE 1.7.0_09的Ubuntu 12.10,以及Unity或Gnome。 Interestingly the java call to isFullScreenSupported() returns true. 有趣的是,对isFullScreenSupported()的java调用返回true。 So, while the Java JRE says it supports full screen exclusive, it doesn't. 因此,尽管Java JRE表示它支持全屏独占,但不支持。

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. 在win7上,使用此代码(我按照@Gilberto的建议将未装饰的标志设置为true并添加了RED面板),似乎可以正常工作。 If it does not work on Ubuntu, then it may mean that FullScreen mode is unsupported: 如果它在Ubuntu上不起作用,则可能表示不支持全屏模式:

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. 该线程非常旧,但仍出现在ACTUAL搜索结果中,但答案有误。 So i'll post actual the real solution. 因此,我将发布实际的实际解决方案。

Swing full screen will be set with the setExtendedState() function, not with the setFullScreenWindow() function! 将使用setExtendedState()函数而不是setFullScreenWindow()函数来设置全屏摆动!

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. 然后,您将拥有一个装饰完整的全屏窗口,其中包含所有按钮和正确的工具栏光学元件,并且可以在Ubuntu和任何其他操作系统上正常工作。

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). 就我而言,我经常需要为我们的大学机构开发Java / Scala应用程序(心理测试)。 To circumpass this issue we decided to install sawfish on our experimental pc's. 为了规避此问题,我们决定在实验PC上安装锯鱼。

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. 如果此解决方案适合您的需求,则可以通过Ubuntu工具(软件中心,Aptitute,apt-get)安装(过时的)锯鱼,或者-我更喜欢-手动安装或编译最新的锯鱼。

Other window and/or desktop managers might give similar functionality, but we experienced artifacts when we tried XFCE or LXDE with disabled/deleted panels. 其他窗口和/或桌面管理器可能会提供类似的功能,但是当我们尝试使用禁用/删除面板的XFCE或LXDE时,我们会遇到构件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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