Apologies that this isn't an answer, but I have the same question and didn't want to duplicate. I tried this:
private void toggleFullScreen() {
GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
dispose();
setUndecorated(true);
gd.setFullScreenWindow(this);
setExtendedState(MAXIMIZED_BOTH);
setVisible(true);
}
The frame appears for a split second and then disappears. Absolutely no idea what I'm doing wrong.
Commenting out setFullScreenWindow and/or setExtendedState results in the same disappearing frame behaviour, just to clarify.