fixed getWindowAncestor() issue in ErrorMessage class.

This commit is contained in:
hneemann 2018-01-22 19:09:06 +01:00
parent fce6e5c4c5
commit bb11b5cd59

View File

@ -117,7 +117,7 @@ public class ErrorMessage implements Runnable {
private String errorMessage;
private ErrorDialog(Component parent, String title, String message) {
super(parent == null ? null : SwingUtilities.getWindowAncestor(parent), title, ModalityType.APPLICATION_MODAL);
super(getParentWindow(parent), title, ModalityType.APPLICATION_MODAL);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
errorMessage = message;
@ -160,4 +160,20 @@ public class ErrorMessage implements Runnable {
}
}
/**
* Get the parent window of the given component.
* If the component is a window this window is returned
*
* @param parent the parent component
* @return the window instance
*/
public static Window getParentWindow(Component parent) {
if (parent == null)
return null;
else if (parent instanceof Window)
return (Window) parent;
else
return SwingUtilities.getWindowAncestor(parent);
}
}