Use SwingUtilities#invokeLater

This ensures that the calls to setExtendedState are thread safe as that
is probably what was causing the occasional game crash before.
This commit is contained in:
Twiglet1022
2019-04-25 23:42:37 +01:00
parent b0195f12f0
commit 223057a136

View File

@@ -602,19 +602,28 @@ public class ClientUI
{ {
if ((frame.getExtendedState() & JFrame.MAXIMIZED_BOTH) == JFrame.MAXIMIZED_BOTH) if ((frame.getExtendedState() & JFrame.MAXIMIZED_BOTH) == JFrame.MAXIMIZED_BOTH)
{ {
frame.setExtendedState(JFrame.ICONIFIED); SwingUtilities.invokeLater(() ->
frame.setExtendedState(JFrame.MAXIMIZED_BOTH); {
frame.setExtendedState(JFrame.ICONIFIED);
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
});
} }
else else
{ {
// If the client is snapped to the edges of the screen, setExtendedState(JFrame.NORMAL) SwingUtilities.invokeLater(() ->
// will undo the snap-to-edge so setSize() is required to prevent the client from {
// changing size. Unfortunately Windows does not support JFrame.MAXIMIZED_VERT // If the client is snapped to the top and bottom edges of the screen, setExtendedState will
int width = frame.getWidth(); // will reset it so setSize and setLocation ensure that the client doesn't move or resize.
int height = frame.getHeight(); // It is done this way because Windows does not support JFrame.MAXIMIZED_VERT
frame.setExtendedState(JFrame.ICONIFIED); int x = frame.getLocation().x;
frame.setExtendedState(JFrame.NORMAL); int y = frame.getLocation().y;
frame.setSize(width, height); int width = frame.getWidth();
int height = frame.getHeight();
frame.setExtendedState(JFrame.ICONIFIED);
frame.setExtendedState(JFrame.NORMAL);
frame.setLocation(x, y);
frame.setSize(width, height);
});
} }
} }