# JFrame Vollbild



## Spitfire777 (12. Jan 2011)

Hi!


Will einen JFrame auf den _ganzen_ (nicht nur maximiert) Bildschirm bringen. Dies soll zu Linux und Windows kompatibel sein. 

Hab alles gemäß API geschrieben, jedoch wird mir der JFrame nur maximiert, dh. die Desktop-Panels unter Ubuntu 10.10 sind noch sichtbar.


```
public class VideoFrame extends javax.swing.JFrame {
    private GraphicsDevice device;

    /** Creates new form VideoFrame */
    public VideoFrame(GraphicsDevice device) {
        super(device.getDefaultConfiguration());
        this.device = device;
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);
        setUndecorated(true);

        jLabel1.setText("Test");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addContainerGap(361, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addContainerGap(273, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>


    public void enterFullScreen() {
        if (device.isFullScreenSupported()) {
            device.setFullScreenWindow(this);
        }
        else {
            JOptionPane.showMessageDialog(this, "Not supported");
        }
    }


    // Variables declaration - do not modify
    private javax.swing.JLabel jLabel1;
    // End of variables declaration

}
```


----------



## CroniD (12. Jan 2011)

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



> Programming Tips
> 
> Here are some tips about programming using full-screen exclusive mode:
> 
> ...


----------



## Enigma228 (12. Jan 2011)

http://www.java-forum.org/buecher-tutorials-links/110214-fullscreen-vollbild-tutorial.html

Aber Vorsicht!! Habe leider immer noch nicht rausgefunden wie Dialogfelder im Fullscreenmodus genutzt werden können!!


----------



## CroniD (13. Jan 2011)

@Enigma228
JDialogs sind Window Objekte. Die können nicht "über" den FullScreen.


			
				http://download.oracle.com/javase/6/docs/api/java/awt/GraphicsDevice.html#setFullScreenWindow%28java.awt.Window%29 hat gesagt.:
			
		

> Windows cannot overlap the full-screen window. All other application windows will always appear beneath the full-screen window in the Z-order.



Aber ... schau dir mal folgendes an:

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

Einfach ein JDesktopPane dem JFrame hinzugefügt und dort die JButtons eingesetzt. Weiterhin muss man nun nur noch die JInternalFrame Klasse benutzen, um die Dialoge zu bauen.
Eine andere Lösung fällt mir jedenfalls nicht ein.

Ach ja, und in dem Quellcode ist auch die Sache mit den dekorierten Fenstern berücksichtigt.


----------



## Enigma228 (20. Jan 2011)

Danke.. 
Ich werde daraufhin mein Tutorial erweitern

Danke Dir!!!


----------

