I've built a swing window in eclipse that goes to fullscreen when opened, however it becomes impossible to toggle the fullscreen off.
I've tried researching online (I am aware of similar threads) but I've come across issues when attempting solutions.
Here is my JFrame
private void initialize()
{
frmCpStats = new JFrame();
frmCpStats.setTitle("CP Stats");
Toolkit tk = Toolkit.getDefaultToolkit();
int x =((int) tk.getScreenSize().getWidth());
int y =((int) tk.getScreenSize().getHeight());
frmCpStats.setExtendedState(JFrame.MAXIMIZED_BOTH);
frmCpStats.setSize(x, y);
frmCpStats.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frmCpStats.setUndecorated(true);
KeyStroke k = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
int w = frmCpStats.WHEN_IN_FOCUSED_WINDOW;
dialog.getRootPane().registerKeyboardAction(e -> window.dispose(), k, w);
}
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
StatsDisplay window = new StatsDisplay();
window.frmCpStats.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public StatsDisplay() {
initialize();
}
Eclipse identifies errors Cannot be resolved or is not a field
with VK_ESCAPE
and WHEN_IN_FOCUSED_WINDOW
, and dialog cannot be resolved
with dialog
. I'm quite unfamiliar with how swing actually works, so I haven't the foggiest idea why these errors are occurring.