maximized_both

Mattepuffo's logo
JFrame full screen

JFrame full screen

Per rendere un JFrame a schermo intero ci sono diversi modi.

Qui vi spiego due modi per avviare un JFrame massimizzato e uno per renderlo a schermo intero.

Cominciamo proprio da quest'ultimo:

import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import javax.swing.JFrame;

public class DrawPanel extends JFrame {

    public DrawPanel() {
        super("Draw panel");
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice cc = ge.getDefaultScreenDevice();
        setVisible(true);
        cc.setFullScreenWindow(this);
    }
}

Nel costruttore del nostro JFrame creiamo un oggetto di classe GraphicsEnvironment il metodo getLocalGraphicsEnvironment().

Sull'oggetto creato richiamiamo il metodo getDefaultScreenDevice() che altro non fa che identificare lo schermo in uso.

Infine setFullScreenWindow mette la finestra in full size (come si evince dallo stesso nome del metodo).