public void setUiVisible(final boolean visible) {
   if (myPopup != null) {
     if (visible) {
       myPopup.show();
       final Window window = getPopupWindow();
       if (window != null && myRestoreWindowSize != null) {
         window.setSize(myRestoreWindowSize);
         myRestoreWindowSize = null;
       }
     } else {
       final Window window = getPopupWindow();
       if (window != null) {
         myRestoreWindowSize = window.getSize();
         window.setVisible(true);
       }
     }
   }
 }
  @Override
  public void pack(boolean width, boolean height) {
    if (!isVisible() || (!width && !height)) return;

    Dimension size = getSize();
    Dimension prefSize = myContent.computePreferredSize();

    if (width) {
      size.width = prefSize.width;
    }

    if (height) {
      size.height = prefSize.height;
    }

    size = computeWindowSize(size);

    final Window window = SwingUtilities.getWindowAncestor(myContent);
    window.setSize(size);
  }