Swing Fullscreen GUI

Hering

Mitglied
Moin,
ich hätte folgende Frage an euch:
Wie schaffe ich es eine Fullscreen-GUI unter Verwendung von JFrames zu schreiben, die auf allen System Fullscreen läuft?
Mein bisheriger Versuch sieht folgendermaßen aus:

Java:
		try {
			JFrame frame = new JFrame("Test"); 
			frame.setSize(64, 64);
			frame.setUndecorated(true); 
			frame.setLocationRelativeTo(null);
			frame.setResizable(false);
			frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
			frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
			frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			frame.setVisible(true);
		} catch (Exception e) {e.printStackTrace();}

Unter Microsoft Windows ist alles in Ordnung, aber unter Linux(speziell OpenSuse) schiebt sich die Taskleiste immer davor. Dieses Verhalten würde ich gerne unterbinden, weiß aber nicht wie.
Hoffe es kann mir jemand helfen.

mfg
Hering
 

JCODA

Top Contributor
Huhu,

vielleicht ist
docs.oracle.com/javase/6/docs/api/java/awt/Window.html#setAlwaysOnTop(boolean)
eine Möglichkeit?

Hab hier kein Linux, deswegen kann ich's auch nicht ausprobieren :/
 

sMau90

Aktives Mitglied
Hey,
Ich hatte zufällig letztens das gleiche Problem. Die folgende Lösung hab ich auch hier irgendwo im Forum gefunden und es funktioniert tatsächlich bis jetzt überall. Warum es genau so klappt, kann ich dir nicht sagen.

Java:
package de.netprojectev.Tests;

import java.awt.FlowLayout;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JFrame;

public class FullscreenWorking extends JFrame implements ActionListener {

	//http://www.java-forum.org/spiele-multimedia-programmierung/137035-ubuntu-gnome3-panel-always-top.html
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JButton gross, klein, exit;

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		FullscreenWorking frame = new FullscreenWorking();
		frame.setVisible(true);
	}

	public FullscreenWorking() {
		setLayout(new FlowLayout());
		gross = new JButton("Groß");
		gross.addActionListener(this);
		klein = new JButton("Klein");
		klein.addActionListener(this);
		exit = new JButton(new AbstractAction("Exit") {
			/**
			 * 
			 */
			private static final long serialVersionUID = -6915307674087790957L;

			@Override
			public void actionPerformed(ActionEvent arg0) {
				System.exit(0);
			}
		});
		add(exit);
		add(gross);
		add(klein);
		pack();
		setDefaultCloseOperation(DISPOSE_ON_CLOSE);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		JButton src = (JButton) e.getSource();
		if (src == gross) {
			GraphicsEnvironment ge = GraphicsEnvironment
					.getLocalGraphicsEnvironment();
			GraphicsDevice myDevice = ge.getDefaultScreenDevice();
			dispose();
			this.setUndecorated(true);
			setVisible(true);
			// this.setAlwaysOnTop(true);
			myDevice.setFullScreenWindow(this);
		} else {
			GraphicsEnvironment ge = GraphicsEnvironment
					.getLocalGraphicsEnvironment();
			GraphicsDevice myDevice = ge.getDefaultScreenDevice();
			dispose();
			this.setUndecorated(false);
			setVisible(true);
			myDevice.setFullScreenWindow(null);
			// this.setAlwaysOnTop(false);
			pack();
		}
	}

}
 

Ähnliche Java Themen

Neue Themen


Oben