private void changeWindowHeightToPreferred() {
    final Window window = ComponentUtil.getWindow(myMainPanel);
    if (window != null) {
      ApplicationManager.getApplication().invokeLater(() -> {
        Dimension currentSize = window.getSize();
        Dimension preferredSize = window.getPreferredSize();
        window.setSize(currentSize.width, preferredSize.height);
      }, ModalityState.stateForComponent(window));
    }
  }
private void changeWindowHeightToPreferred()