title: Custom JComboBox hiding JPopupMenu
body: <p>I'm having a little headache with a situation. Maybe some of you have been through this before and can show me another way or even my error here.</p>
  
  <p>I need to add a JTree inside a JComboBox and the code below works like a charm.</p>
  
  <pre><code>public class HierarchyComboBox extends JComboBox {
      HierarchyTree ht = new HierarchyTree();
      HierarchyComboBox box;
      JPopupMenu popup;
      MouseAdapter adapter = new MouseAdapter() { 
          @Override
          public void mouseClicked(MouseEvent arg0) {
              if (arg0.getClickCount() == 1) {
                  removeAllItems();
                  addItem(ht.getSelectedLevel());
  //              ((JPopupMenu) comp).setVisible(false);
              }
          }
      };
  
  
      PopupMenuListener listener = new PopupMenuListener() {
          @Override
          public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
              if (box == null) {
                  box = (HierarchyComboBox) e.getSource();
                  if (popup == null) {
                      final Object comp = box.getUI().getAccessibleChild(box, 0);
                      if (!(comp instanceof JPopupMenu))
                          return;
                      popup = (JPopupMenu) comp;
                  }
                  popup.removeAll();
                  ht.getTreePane().setBorder(null);
                  ht.getTreePane().setPreferredSize(new Dimension(box.getWidth(), 200));
                  MyTree tree = (MyTree)ht.getTreePane().getViewport().getComponent(0);
                  tree.addMouseListener(adapter);
                  popup.add(ht.getTreePane());
              }
          }
          @Override
          public void popupMenuCanceled(PopupMenuEvent arg0) { }
          @Override
          public void popupMenuWillBecomeInvisible(PopupMenuEvent arg0) { }
      };
  
      public HierarchyComboBox() {
          setEditable(true);
          addPopupMenuListener(listener);
      }
  }
  </code></pre>
  
  <p>but I added this component to 2 different dialogs. <br/>
  The first one I can click and the selection is added to the JComboBox</p>
  
  <p>and the second, doing EXACTLY the same instantiation, and the same tests<br/><br/>
  The component has a different behaviour:<br/>
   - The JPopupMenu disappears<br/>
   - It doesn't add the selection to the combo<br/></p>
  
  <p>Any ideas here?<br/>
  Thanks in advance..</p>