Java: How to fullscreen and back?
Hello I was wondering how I can undecorate and then redecorate a window made by a Java Frame application for JOGL, WITHOUT destroying it and recreating it again. It causes some objects to become null after destroying the window to either go to fullscreen or windowed mode. If it is possible ofcourse.
Thanks.
Well it seems as though u still call the dispose() method so that invalidates all the JOGL functions such as animator etc. And you can not undecorate a window when it is already drawn so u have to call dispose and then undecorate the new window, which destroys the previous window. That's as far as I know. Thanks for reply.





See example below.
Part of code taken from here: http://docs.oracle.com/javase/tutorial/extra/fullscreen/example-1dot4/Di...
import java.awt.BorderLayout;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
public class RedecorateTest extends JFrame {
public static void main(String[] args) {
JFrame frame = new RedecorateTest();
frame.pack();
frame.setVisible(true);
}
JButton redecorate;
GraphicsDevice device;
JButton button = new JButton("Swap Mode");
public RedecorateTest() {
super("RedecorateTest");
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
device = env.getScreenDevices()[0];
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
swap();
}
});
getContentPane().add(button, BorderLayout.NORTH);
}
void swap() {
Window fsw = device.getFullScreenWindow();
setVisible(false);
dispose();
boolean goFullScreen = fsw != this;
System.out.println(fsw + " " + this);
setUndecorated(goFullScreen);
setResizable(!goFullScreen);
if (goFullScreen) {
button.setText("FULL SCREEN MODE");
device.setFullScreenWindow(this);
validate();
} else {
device.setFullScreenWindow(null);
button.setText("WINDOWED MODE");
pack();
setVisible(true);
}
}
}