Skip to main content

Java: How to fullscreen and back?

2 replies [Last post]
Thentos
Offline
Joined: 2012-01-08
Points: 0

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.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
imagero
Offline
Joined: 2003-11-18
Points: 0

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

Thentos
Offline
Joined: 2012-01-08
Points: 0

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.