mirror of
https://github.com/magefree/mage.git
synced 2025-12-24 20:41:58 -08:00
Fixed NullPointerException thrown time to time for ability picker shown for cards in hand.
This commit is contained in:
parent
65c55e4e2a
commit
8a454d38a7
1 changed files with 20 additions and 14 deletions
|
|
@ -4,6 +4,7 @@ import java.awt.Color;
|
|||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.GraphicsConfiguration;
|
||||
import java.awt.Insets;
|
||||
|
||||
import javax.swing.JButton;
|
||||
|
|
@ -107,20 +108,25 @@ public class GuiDisplayUtil {
|
|||
|
||||
public static void keepComponentInsideScreen(int x, int y, Component c) {
|
||||
Dimension screenDim = c.getToolkit().getScreenSize();
|
||||
Insets insets = c.getToolkit().getScreenInsets(c.getGraphicsConfiguration());
|
||||
|
||||
if (x + c.getWidth() > screenDim.width - insets.right) {
|
||||
x = (screenDim.width - insets.right) - c.getWidth();
|
||||
} else if (x < insets.left) {
|
||||
x = insets.left;
|
||||
GraphicsConfiguration g = c.getGraphicsConfiguration();
|
||||
if (g != null) {
|
||||
Insets insets = c.getToolkit().getScreenInsets(g);
|
||||
|
||||
if (x + c.getWidth() > screenDim.width - insets.right) {
|
||||
x = (screenDim.width - insets.right) - c.getWidth();
|
||||
} else if (x < insets.left) {
|
||||
x = insets.left;
|
||||
}
|
||||
|
||||
if (y + c.getHeight() > screenDim.height - insets.bottom) {
|
||||
y = (screenDim.height - insets.bottom) - c.getHeight();
|
||||
} else if (y < insets.top) {
|
||||
y = insets.top;
|
||||
}
|
||||
|
||||
c.setLocation(x, y);
|
||||
} else {
|
||||
System.out.println("null");
|
||||
}
|
||||
|
||||
if (y + c.getHeight() > screenDim.height - insets.bottom) {
|
||||
y = (screenDim.height - insets.bottom) - c.getHeight();
|
||||
} else if (y < insets.top) {
|
||||
y = insets.top;
|
||||
}
|
||||
|
||||
c.setLocation(x, y);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue