tags:

views:

65

answers:

4

Hi,

I need a tool which tells the classname of the UI control on which my mouse pointer is. My GUI is in Swing. Does such a tool exist?

A: 

It should be possible to write a mouse listener doing such thing.

iny
+1  A: 

If you need to discover this within the program itself, you can use a MouseListener and the sequence:

Event.getSource()
Object.getClass()
Class.getName()
Software Monkey
+3  A: 

You can get the current location of the mouse pointer by doing:

Point location = MousePointer.getPointerInfo().getLocation();

Once you have the location, you can convert it to your parent containers coordinate system by doing:

Point relativeLocation = SwingUtilities.convertPointFromScreen(location, parentComponent);

Finally, you can lookup a component at a location by doing:

Component myComponent = parentComponent.getComponentAt(relativeLocation);
Outlaw Programmer
+3  A: 

Check out Swing Explorer. It allows you to explore the internals of your Swing app.

Craig