As a succession to this post I\'m running into an infinite loop that causes my computer to crash. Or, well, not quite: it seems to cause the Java window (JFrame) to keep getting
I'm not entirely sure why you are invoking both
getInstance().setExtendedState(JFrame.ICONIFIED);
getInstance().setExtendedState(JFrame.NORMAL);
but if you remove the first, i.e. simply:
getInstance().setExtendedState(JFrame.NORMAL);
then it just opens the window once, without the infinite looping you describe.
The reason your code causes an infinite loop is that it minimizes and then unminimizes the frame, which results in the windowActivated
method being run: this invokes the refresh
method, which invokes the bringToFront
method, which minimizes and unminimizes the frame etc.
To actually bring the window to the front, the following works for me, based upon this question:
private static void bringToFront() {
getInstance().setVisible(true);
getInstance().setExtendedState(JFrame.NORMAL);
getInstance().toFront();
getInstance().repaint();
}