# Fullscreen / Vollbild Tutorial



## Enigma228 (8. Dez 2010)

Quelle:
Full-Screen Exclusive Mode (The Java™ Tutorials > Bonus > Full-Screen Exclusive Mode API)

FullScreen / Vollbild wird von der Klasse GraphicsDevice gehandhabt.

1. Zuerst holt man sich die DisplayModi
Klasse:     GraphicsEnvironment
Methode: getScreenDevices() -> man erhält ein Array mit GraphicsDevices.
oder:       getDefaultScreenDevice() -> man erhält ein GraphicsDevice mit aktueller Auflösung


```
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice device;
device =ge.getDefaultScreenDevice();
```

2. Überprüfung ob Fullsize unterstützt wird
Klasse: GraphicsDevice
Methode: isFullScreenSupported() -> man erhält einen boolean-Wert.

3. Setzen des FullSize-Modus
Klasse: GraphicsDevice
Methode: setFullScreenWindow(Window w) -> FullScreen wird eingestellt
oder: setFullScreenWindow(null) -> um auf "normale" Grösse zurückzustellen


```
if(device.isFullScreenSupported()){
			device.setFullScreenWindow(this);
}
```

Hier mal eine einfache JFrame-Klasse in dem der User zwischen dem FullScreen- und dem Fenster-Modus hin und herschalten kann.


```
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

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


public class MyFrame extends JFrame implements ActionListener{

	private JButton b_close, b_larger, b_smaller;
	private GraphicsDevice device;
    
	
	public MyFrame() throws HeadlessException {
		this.setLayout(null);
		this.setSize(500,500);
		this.setLocationRelativeTo(null);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
		device =ge.getDefaultScreenDevice();

		if(device.isFullScreenSupported()){
			device.setFullScreenWindow(this);
		}
		
		
		b_close = new JButton("Beenden");
		b_close.setBounds(20, 20, 100, 30);
		b_close.addActionListener(this);
		
		b_larger = new JButton("FullScreen");
		b_larger.setBounds(20, 70, 100, 30);
		b_larger.addActionListener(this);
		b_larger.setEnabled(false);
		
		b_smaller = new JButton("Window");
		b_smaller.setBounds(20, 120, 100, 30);
		b_smaller.addActionListener(this);
		
		this.add(b_close);
		this.add(b_smaller);
		this.add(b_larger);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getSource()== b_close){
			device.setFullScreenWindow(null);
            System.exit(0);
		}
		if(e.getSource()== b_larger){
			b_larger.setEnabled(false);
			b_smaller.setEnabled(true);
			device.setFullScreenWindow(this);
		}
		if(e.getSource()== b_smaller){
			b_larger.setEnabled(true);
			b_smaller.setEnabled(false);
			device.setFullScreenWindow(null);
		}
	}

	
}
```

Viel Spass beim Testen !!!


----------



## Enigma228 (20. Jan 2011)

DANKE an CroniD!!!!

Dialogfelder im Fullscreen lassen sich nur an das JDesktopPane binden, da 
"JDialogs sind Window Objekte. Die können nicht "über" den FullScreen." (Zitat CroniD)

"Windows cannot overlap the full-screen window. All other application windows will always appear beneath the full-screen window in the Z-order."
Zitat aus: 
GraphicsDevice (Java Platform SE 6)

Bsp. von CroniD
nochmals Danke!!!

```
import java.awt.BorderLayout;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
 
import javax.swing.JButton;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
 
public class FullScreenSwing extends JFrame implements ActionListener {
 
    private JDesktopPane d_pane;
    private JButton b_close, b_larger, b_smaller, b_dialog;
    private GraphicsDevice device;
    
    public FullScreenSwing() throws HeadlessException {
        this.setLayout(new BorderLayout());
        this.setSize(500,500);
        this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        device = ge.getDefaultScreenDevice();
 
        if (device.isFullScreenSupported()){
            setUndecorated(true);
            device.setFullScreenWindow(this);
        }
        b_close = new JButton("Close");
        b_close.setBounds(20, 20, 100, 30);
        b_close.addActionListener(this);
        
        b_larger = new JButton("FullScreen");
        b_larger.setBounds(20, 70, 100, 30);
        b_larger.addActionListener(this);
        b_larger.setEnabled(false);
        
        b_smaller = new JButton("Window");
        b_smaller.setBounds(20, 120, 100, 30);
        b_smaller.addActionListener(this);
        
        b_dialog = new JButton("Show Dialog");
        b_dialog.setBounds(20, 170, 100, 30);
        b_dialog.addActionListener(this);
        
        d_pane = new JDesktopPane();
        d_pane.setBackground(null); // prevent unexpected LaF settings
        d_pane.add(b_close);
        d_pane.add(b_smaller);
        d_pane.add(b_larger);
        d_pane.add(b_dialog);
        this.add(d_pane);
    }
 
    @Override public void actionPerformed(ActionEvent e) {
        if (e.getSource() == b_close) {
            device.setFullScreenWindow(null);
            System.exit(0);
        }
        if (e.getSource() == b_larger) {
            b_larger.setEnabled(false);
            b_smaller.setEnabled(true);
            if (isDisplayable()) {
                setVisible(false);
                dispose();
            }
            setUndecorated(true);
            if (!isVisible()) {
                setVisible(true);
            }
            device.setFullScreenWindow(this);
        }
        if (e.getSource() == b_smaller) {
            b_larger.setEnabled(true);
            b_smaller.setEnabled(false);
            device.setFullScreenWindow(null);
            setVisible(false);
            dispose();
            setUndecorated(false);
            setVisible(true);
        }
        if (e.getSource() == b_dialog) {
            // is window in full screen mode?
            if (device.getFullScreenWindow() == null) {
                JOptionPane.showMessageDialog(this, "This is a test dialog.");
            } else { // isFullScreen
                JOptionPane.showInternalMessageDialog(d_pane, "This is a test dialog.");
            }
        }
    }
    
    public static void main(String[] args) {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception e) { e.printStackTrace(); }
        new FullScreenSwing().setVisible(true);
    }
}
```


----------

