public static Component getDefaultComponentInPanel(Component component) {
    if (!(component instanceof JPanel container)) {
      return null;
    }

    FocusTraversalPolicy policy = container.getFocusTraversalPolicy();
    if (policy == null) {
      return container;
    }

    final Component defaultComponent = policy.getDefaultComponent(container);
    if (defaultComponent == null) {
      return container;
    }
    return policy.getDefaultComponent(container);
  }
public static Component getDefaultComponentInPanel(Component component)