Hi,
I think this is a hard one. I've been looking around the net on how to
do this, can't find any info.
Firstly is this hard to implement?
The problem:
I have a JPanel. What I want to happen is some predetermined text to
appear over the mouse or in a JTextField on another panel, when the
mouse moves over or within 5 pixels of different coordinates. Text
above the mouse would be my prefferable implementation.
What do I need to look at to findout how this can be implemented?
Thanks again.
Ben.
Ian Mills - 12 Feb 2006 09:43 GMT
> Hi,
>
[quoted text clipped - 14 lines]
>
> Ben.
Try looking at MouseMotionListener as a starting point or maybe
MouseMotionAdapter.
Ben - 12 Feb 2006 15:51 GMT
Hi,
I took your advice and came up with the following. I have a class that
initialises the MouseMotion class (code below). In the initialising
class I have also used
ToolTipManager.sharedInstance().setEnabled(true); to enable the
tooltips for the whole application. I also added the listener to a
panel using panel1.addMouseMotionListener(mouseListener);. (adding
tooltips to buttons etc works fine)
The code below prints a line to the screen when the mouse is moved over
a coordinate on the panel. How do I change this to a tooltip?
Thanks for any help.
Ben.
import java.awt.*;
import java.awt.event.*;
public class MouseMotion implements MouseMotionListener
{
// The X-coordinate and Y-coordinate ofthe last Mouse Position.
int xpos;
int ypos;
public void mouseMoved(MouseEvent me)
{
xpos = me.getX();
ypos = me.getY();
if(xpos = 10 && y pos == 10)
{
System.out.println("Area 1");
}
if(xpos = 20 && y pos == 20)
{
System.out.println("Area 2");
}
if(xpos = 30 && y pos == 30)
{
System.out.println("Area 3");
}
}
public void mouseDragged(MouseEvent me)
{
}
}
Ian Mills - 12 Feb 2006 17:22 GMT
> Hi,
>
[quoted text clipped - 46 lines]
> }
> }
I haven't done this myself but you could try creating a JToolTip (using
the createToolTip() method) then doing a setTipText and setVisible(true)
where you are doing your System.out.println