Question

I have a problem to run Java application in full screen mode on "openSUSE 11.4 (x86_64)". I am using Java 1.6.0_26-b03.

I have try to run two examples of full screen application:

  1. Example from Oracle site: Display Mode Test.
  2. JDarkRoom.jar (simple text editor) downloaded from Codealchemists.

In both cases I have a Linux Task bar visible over the application. It must be something with system settings/configuration?

Was it helpful?

Solution

You should be able to go “really full screen” with GraphicsDevice.setFullScreenWindow (window). However, due to bugs in the most popular Java runtimes, this may not work on systems running certain “broken” versions in the 1.6 = Java 6 series. I haven't tested this thoroughly, so it may be that the patch hasn't propagated out to the general populace, yet.

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7057287

Background/Theory

OK, so here goes for too much information, and not enough help… Here's a bit of why this didn't work right…

There is no Linux Desktop

Linux-based operating systems on PC-type machines, as well as other Unices (with a partial exception for MacOSX), normally use the X Window System (aka X11). Under X, you have an X Server (usually, something kinda like a “video driver”) and clients that connect to it, more often than not, from the same machine (loopback).

The layout and placement of windows is controlled by a special client program, called the Window Manager. It's responsible for decorating the windows (e.g. drawing title bars or resize handles) and positioning them.

Your program would be an X client. It can request — but not demand — placement on the screen at a certain position, or a certain size. Various Window Managers are more (or less) prone to giving you what you want.

Except, most desktops play nicely (sometimes)

Now, by far, most Linux desktops use the Gnome Desktop, with a strong second place for the K Desktop, and a few others are in fairly wide use. What's “nice” is that both of these desktop environments (as well as some others, like XFCE for low-end PC's) conform to the FreeDesktop.org Window Manager Hints standards.

(Super-over-simplification:) Typically, there will be Panels on one or more edges of the screen. Usually, there's just one, across the top, but there are many variations. These Panel areas are not considered “part of the screen,” so the Window Manager tells your application, “no, that's outside of the area in which you're allowed to play; this screen is not 1920×1080, it's only 1890×1080.” Of course, that could be totally different arrangement than what you'd anticipated when you wrote your app, and you might be on my netbook with a physical screen of 800×480 pretending to be only 780×480.

For 99% of apps, that's great. Windows don't get in the way of the Panels, so you can always reach the Panel for critical controls, like hitting Mute or switching to another program or something.

These “hints” allow you to request that your top-level windows get treated specially. For example, you can request that you get no title bar — or a reduced, “palette” type title bar; you can request to be skipped on the window list or task bar or activities overview or whatever other interface might be used to show the active windows; or, you can request to go really full-screen, and push everything else out of the way, even panels.

The spec is here: http://standards.freedesktop.org/wm-spec/wm-spec-latest.html

And the Fail:

Basically, the window manager hints specification wasn't being followed correctly by Sun/Oracle (or Red Hat, who copied off Sun/Oracle, or probably IBM, because they probably did the same, but I don't see anybody complaining about them)…

Although, I do see some griping back and forth about whether it's a bug (specifically) with the K Desktop Environment's window manager (KWin), as apparently this bug only shows up in K, and not in Gnome, XFCE, and friends.

Work-Around

Aside from patching your Java runtimes (and/or your customers'), the only real fix would be to use the platform-specific Java libraries (perhaps grab the underlying AWT objects using reflection… eww…) and set the proper window hints, yourself.

Yes, that's gross…

OTHER TIPS

Just a precision on the method of bgroenks:
It's work fine with java7 and java8 on Ubuntu 14.10 (Unity).

BUT: You must set frame.setResizable(true); otherwise, it won't work.

Be careful: the fullscreen mode only works with JFrame (no JDialog or JWindow).

Here a sample code: It takes place of setVisible(true)

/**
 * @param frame
 * @param doPack
 * @return device.isFullScreenSupported
 */
static public boolean fullScreen(final JFrame frame, boolean doPack) {

    GraphicsDevice device = frame.getGraphicsConfiguration().getDevice();
    boolean result = device.isFullScreenSupported();

    if (result) {
        frame.setUndecorated(true);
        frame.setResizable(true);

        frame.addFocusListener(new FocusListener() {

            @Override
            public void focusGained(FocusEvent arg0) {
                frame.setAlwaysOnTop(true);
            }

            @Override
            public void focusLost(FocusEvent arg0) {
                frame.setAlwaysOnTop(false);
            }
        });

        if (doPack)
            frame.pack();

        device.setFullScreenWindow(frame);
    }
    else {
        frame.setPreferredSize(frame.getGraphicsConfiguration().getBounds().getSize());

        if (doPack)
            frame.pack();

        frame.setResizable(true);

        frame.setExtendedState(Frame.MAXIMIZED_BOTH);
        boolean successful = frame.getExtendedState() == Frame.MAXIMIZED_BOTH;

        frame.setVisible(true);

        if (!successful)
            frame.setExtendedState(Frame.MAXIMIZED_BOTH);
    }
    return result;
}

Regards, Stéphane.

I realize this question is a bit old, but I stumbled upon it looking for the same answer.

After a lot of experimenting, I came up with a good solution:

GraphicsDevice d = GraphicsEnvironment
    .getLocalGraphicsEnvironment().getDefaultScreenDevice();
if (d.isFullScreenSupported()) {
    frame.setUndecorated(true);
    frame.setResizable(false);
    frame.addFocusListener(new FocusListener() {

        @Override
        public void focusGained(FocusEvent arg0) {
            frame.setAlwaysOnTop(true);
        }

        @Override
        public void focusLost(FocusEvent arg0) {
            frame.setAlwaysOnTop(false);
        }
    });
    d.setFullScreenWindow(frame);
} else {
    frame.setVisible(true);
}

The focus listener is so the user can ALT-TAB or META-D out of the window without it immediately forcing re-focus.

This works on my Linux Mint 15 system with KDE 4. I am also using a NVIDIA X-Server.

Hope this helps! Let me know if it works for you guys too!

None of the above worked for me, I'm using XUbuntu, But I just tried using a JWindow instead of a JFrame and it worked! That was so frustrating, hopefully it works for you. Oh I should mention I haven't looked at the API yet and I'm really not familiar with the JWindow class so I'm not sure exactly what the differences are between a JWindow and a JFrame. Good luck.

I've used Oracle Java editions 1.6.0_31 and 1.6.0_26 using full screen mode. I experienced some of the troubles with the window not showing above the taskbar on Ubuntu. However I was able to make it work with this little code sample.

// Create a window for full-screen mode; add a button to leave full-screen mode
GraphicsDevice gs = GraphicsEnvironment.getLocalGraphicsEnvironment().
                    getDefaultScreenDevice(); 
                    //or initialize this for a specific display
Frame frame = new Frame(gs.getDefaultConfiguration());
Window win = new Window(frame);
Canvas c = new Canvas();
c.setBackground(Color.RED);
win.add(c);
win.show();  //or setVisible(true);

// Enter full-screen mode
gs.setFullScreenWindow(win);
win.validate();

The trick that worked is making the window visible first, then placing the window in full screen mode. Setting full screen mode before it's shown resulted in the task bar above the window.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top