Hi all,
I previously sent a tooltip implementation using a JWindow to another
list that will solves your problem also. The code is in the forwarded
email far below. This is how you can use it in a Canvas3D:

public class ViewDlg extends JDialog
{
   private View3D view3D;
   private SiteTree siteTree;
   private PopupTip popup = new PopupTip(); //this is the class

   public Site3DView()
   {
      JPanel panel = new JPanel(new BorderLayout());
      view3D = new View3D();

      this.getContentPane().add(panel);
      Dimension dim  = this.getToolkit().getScreenSize();
      setBounds((int) (dim.width*.5-350), (int) (dim.height*.5-350),700,
700);

      siteTree = new SiteTree();

      JSplitPane tSplitPane = new
JSplitPane(JSplitPane.HORIZONTAL_SPLIT, siteTree, new JScrollPane(view3D));
      tSplitPane.setLastDividerLocation(200);
      panel.add(tSplitPane,BorderLayout.CENTER);
      setVisible(true);
   }

   public class View3D extends JPanel
   {
      Canvas3D canvas3D = new
Canvas3D(SimpleUniverse.getPreferredConfiguration());
      SimpleUniverse simpleU = new SimpleUniverse(canvas3D);
      TransformGroup rootTransG = new TransformGroup();
      BranchGroup rootBranchG = new BranchGroup();
      public View3D()
      {
         rootBranchG.setCapability(BranchGroup.ALLOW_DETACH);
         simpleU.getViewingPlatform().setNominalViewingTransform();
         this.setLayout( new BorderLayout() );
         this.setOpaque( false );
         this.add("Center", canvas3D);

         canvas3D.addMouseMotionListener(new MouseMotionAdapter()
         {
            public void mouseMoved(MouseEvent e)
            {
               Point pt = e.getPoint();
               popup.showAt(pt.x + ","+pt.y,view3D,pt.x,pt.y,100,15);
            }
         });
      }
    }
}

> Hi all,
> I thought it would be nice if I share my version of a Tooltip that can
> be used on a layer. The CustomToolTip listed at the bottom is a simple
> JWindow and can be modified to contain any Component or JComponent and
> can be used pretty much anywhere.
>
> Have fun customizing it,
> -Chinh
>
> This is how you would use it on a layer that is listening to a
> mouseMove():
>
>   CustomToolTip customToolTip = new CustomToolTip();    public void
> mouseMoved(MouseEvent e)
>   {
>        Point pt = e.getPoint();
>        //somehow in your implementation, get the OMGraphicList
>        OMGraphicList graphicList = getOMGraphicList();
>        //find the node at this point
>        OMGraphic om = graphicList.findClosest(pt.x,pt.y,2);
>
>        if (om!=null)
>           customToolTip.showAt(om.getAppObject().toString(), this,
> ptMouse.x,ptMouse.y);
>        else
>           customToolTip.setVisible(false);
>    }
>
>
>
>
> 
>/**////////////////////////////////////////////////////////////////////////////////////////////////////////
>
> *    tooltip that can be used anywhere
> 
>**/////////////////////////////////////////////////////////////////////////////////////////////////////////
>
> public class CustomToolTip extends JWindow
>   {
>      JLabel label = new JLabel("");
>      public CustomToolTip()
>      {
>         this.setVisible(false);
>         Container con = this.getContentPane();
>         con.add(label);
>         label.setBorder(BorderFactory.createRaisedBevelBorder());
>         con.setBackground(Color.yellow.brighter().brighter());
>         con.setForeground(Color.black);
>         label.setOpaque(false);
>      }
>
>      private static Frame getFrame(Component c)
>      {
>         Component w = c;
>         while(!(w instanceof Frame) && (w!=null)) {
>             w = w.getParent();
>         }
>         return (Frame)w;
>      }
>
>      public void showAt(String s, Component invoker, int x, int y)
>      {
>          int width=100, int height=30;
>          label.setText(s);
>          if (invoker != null)
>          {
>             Point invokerOrigin = invoker.getLocationOnScreen();
>             x += invokerOrigin.x;
>             y += invokerOrigin.y;
>            Frame frame = getFrame(invoker);
>            Graphics g = frame.getGraphics();
>            Rectangle2D rec = g.getFontMetrics().getStringBounds(s,g);

               g.dispose();
           width = rec.getWidth();
           height = rec.getHeight();
         }
         this.setBounds(x+15,y+15,width+7, height+7);
         this.setVisible(true);
         this.toFront();
     }
  }



Ashish Aggarwal wrote:

>Hi,
>
>How can I use JTooltip on a canvas3D. The problem is that, to register a component 
>with JToolTip object, one has to use the follwing function:
>
>setComponent(JComponent c)
>
>Since Canvas3D is not a JComponent, I can't do it (even after doing casting from 
>Component to JComponent). On the other hand,I was able to use JPopupMenu on canvas3D 
>but it shows unpredictable behavior. It shows up only with some objects in the scene 
>and that too in some special orientation of that object. I posted my query earlier 
>too but didn't receive any reply. Can somebody please explain me this.
>
>FYI: I am making both JpopUpMenu and ToolTipManager heavyweight components.
>
>
>Ashish
>
>===========================================================================
>To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
>of the message "signoff JAVA3D-INTEREST".  For general help, send email to
>[EMAIL PROTECTED] and include in the body of the message "help".
>

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to