Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Full Screen toggle problem

807591Apr 30 2008 — edited May 2 2008
Hello

I have a problem with a JFrame, I want the window to have the option of being fullscreen with an event, and without the decorate of the window, but when I try to turn off the decorated the JFrame must not be displayable, I tried with JFrame.setVisible(false) but I only managed to make it work by disposing thw object before entering fullscreen mode, the problem is that if I have something displayed in the JFrame (like the sample text in the code below) it dissapears in the fullscreen mode and if I call the method I made for painting the sample text, it doesnt appear, why is that?.

So my question Is how do I toggle to Full Screen and without decorate of the frame without loosing the things painted in the JFrame

some code for you to look at:
import javax.swing.JFrame;
import java.awt.GraphicsEnvironment;
import java.awt.GraphicsDevice;
import java.awt.Color;
import java.awt.Graphics;

public class VentanaGrafica {
    
    private JFrame ventanaG;
    private boolean full;
    
    
    public VentanaGrafica (){
    
        ventanaG = new JFrame("Nombre del programa");
        ventanaG.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        ventanaG.setSize(800, 600);
        ventanaG.setVisible(true);
        full = false;
        
    }
    
    public void setFullScreen(){
        
        if (full == false){ 
            // Modo Pantalla Completa          
            ventanaG.dispose();
            ventanaG.setVisible(false);
            ventanaG.setUndecorated(true);
        
            ventanaG.setResizable(false);
    
            GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
            GraphicsDevice device = environment.getDefaultScreenDevice();
            device.setFullScreenWindow(ventanaG);
            ventanaG.setVisible(true);
            
            full = true;
        }
        else{
            // Modo Ventana
            ventanaG.dispose();
            ventanaG.repaint();
            ventanaG.setVisible(false);
            ventanaG.setUndecorated(false);
            ventanaG.setResizable(true);
            GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
            GraphicsDevice device = environment.getDefaultScreenDevice();
            device.setFullScreenWindow(null);
            ventanaG.setVisible(true);
            full = false;
        }
        
    }
    
        
    public void paint(){
    
        Graphics g = ventanaG.getGraphics();
        g.drawString("Sample text", 100, 100);
        
        
    }

}
and the main mode:
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        VentanaGrafica test = new VentanaGrafica();
        test.paint();
        test.setFullScreen();
        test.paint();
        
        
        
        
    }

}
Sorry for the long post but I really need some help or advice, thanks for reading
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 30 2008
Added on Apr 30 2008
6 comments
515 views