private static @Nullable JLayeredPane getLayeredPane(@Nullable Component aComponent) {
    if (aComponent == null) {
      return null;
    }
    else if (aComponent instanceof JLayeredPane) {
      return (JLayeredPane)aComponent;
    }
    else if (aComponent instanceof JFrame) {
      return ((JFrame)aComponent).getRootPane().getLayeredPane();
    }
    else if (aComponent instanceof JDialog) {
      return ((JDialog)aComponent).getRootPane().getLayeredPane();
    }

    Window window = SwingUtilities.getWindowAncestor(aComponent);
    if (window instanceof JFrame) {
      return ((JFrame)window).getRootPane().getLayeredPane();
    }
    else if (window instanceof JDialog) {
      return ((JDialog)window).getRootPane().getLayeredPane();
    }
    return null;
  }
private static @Nullable JLayeredPane getLayeredPane(@Nullable Component aComponent)