Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2006

Tip: Looking for answers? Try searching our database.

Text displayed when mouse a coordinate

Thread view: 
Ben - 12 Feb 2006 00:01 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.