Exemplo n.º 1
0
    public void show() {
      Component component = getComponent();
      Container parent = null;

      if (owner != null) {
        parent = owner.getParent();
      }
      /*
      Find the top level window,
      if it has a layered pane,
      add to that, otherwise
      add to the window. */
      while (!(parent instanceof Window || parent instanceof Applet) && (parent != null)) {
        parent = parent.getParent();
      }
      // Set the visibility to false before adding to workaround a
      // bug in Solaris in which the Popup gets added at the wrong
      // location, which will result in a mouseExit, which will then
      // result in the ToolTip being removed.
      if (parent instanceof RootPaneContainer) {
        parent = ((RootPaneContainer) parent).getLayeredPane();
        Point p = SwingUtilities.convertScreenLocationToParent(parent, x, y);
        component.setVisible(false);
        component.setLocation(p.x, p.y);
        parent.add(component, JLayeredPane.POPUP_LAYER, 0);
      } else {
        Point p = SwingUtilities.convertScreenLocationToParent(parent, x, y);

        component.setLocation(p.x, p.y);
        component.setVisible(false);
        parent.add(component);
      }
      component.setVisible(true);
    }
Exemplo n.º 2
0
    public void show() {
      Container parent = null;

      if (owner != null) {
        parent = (owner instanceof Container ? (Container) owner : owner.getParent());
      }

      // Try to find a JLayeredPane and Window to add
      for (Container p = parent; p != null; p = p.getParent()) {
        if (p instanceof JRootPane) {
          if (p.getParent() instanceof JInternalFrame) {
            continue;
          }
          parent = ((JRootPane) p).getLayeredPane();
          // Continue, so that if there is a higher JRootPane, we'll
          // pick it up.
        } else if (p instanceof Window) {
          if (parent == null) {
            parent = p;
          }
          break;
        } else if (p instanceof JApplet) {
          // Painting code stops at Applets, we don't want
          // to add to a Component above an Applet otherwise
          // you'll never see it painted.
          break;
        }
      }

      Point p = SwingUtilities.convertScreenLocationToParent(parent, x, y);
      Component component = getComponent();

      component.setLocation(p.x, p.y);
      if (parent instanceof JLayeredPane) {
        parent.add(component, JLayeredPane.POPUP_LAYER, 0);
      } else {
        parent.add(component);
      }
    }