Get Location X and Y of Mouse Cursor in Table-View Form

Hi, I am trying to get the location x and location y of the mouse cursor when I right click a form in table view.

I tried to use the following but it always gave the x and y coordinates of the selected record:

var mouse = java.awt.MouseInfo.getPointerInfo().getLocation();
var x = mouse.x;
var y = mouse.y;

I also tried JSEvent’s getLocationX() and getLocationY(), and it still did the same thing.

Is there a way to get the mouse pointer’s x and y coordinates on the form regardless whether if it’s clicking an element or not?

java.awt.MouseInfo.getPointerInfo().getLocation();

that should give you the current position where the mouse is, but isn’t that the always the selected record?

Thanks for the reply.

Nope, when I right click on a column header, it doesn’t actually select a record, right? It should just trigger the onRightClick method and give the x and y coordinates of the mouse pointer.

Let’s say if I select the 5th record from the top, and then perform a right click on the header, I should retrieve the X and Y coordinates near the column header and not of the selected record. Is this a Servoy limitation? Is there a workaround on this?

this call:

java.awt.MouseInfo.getPointerInfo().getLocation();

is pure java, there is no servoy code related at all, so that just should give you the mouse position where the mouse is at that time

I have the same issue here.

I want to rightclick on a table-view and showup a popmenu on the mouse position.

So I do this:

	var vObject = java.awt.MouseInfo.getPointerInfo().getLocation()
	var x = vObject.x
	var y = vObject.y
         vPopupmenu.show(x,y);

It works (sort of) when I have the window of the smart-client maximized!
but it goes totally wrong when run the smart-client in a smaller window. The position of where the popupmenu appears, is totally different

So I believe this function, returns the x and y position of the whole screen, instead of relative inside the servoy solution.

Does anyone know a workaround or solution??

you need to call: http://docs.oracle.com/javase/7/docs/ap … mponent%29
i guess
but that only really works in a small plugin

I do not know if it solves Your issue, but I needed this functionality for buttons.
To show a dialogue on the button position ( even if the solution window is small).
I use the It2Be tools plugin :

// Get the x coordinate of the element relative to the screen...
var button = elements.button;

// calculate the new x coordinate for the dialog.
var x = plugins.it2be_tools.getScreenX(button) - button.getLocationX();

// calculate the new y coordinate for the dialog.
var y = plugins.it2be_tools.getScreenY(button) + button.getHeight() - button.getLocationY();

application.showFormInDialog(forms.name, x, y);

Hans, I tried that but it’s not working, I got the same issue, as I described above.

function showActionMenu(vEvent)
{
	var vPopupmenu = plugins.window.createPopupMenu()
	var vMenuItem1 = vPopupmenu.addMenuItem('i18n:1.markasread', startAction, 'media:///envelope_open.gif')
	var vMenuItem2 = vPopupmenu.addMenuItem('i18n:1.markasunread', startAction, 'media:///envelope_closed.gif')
//	var vMenuItem3 = vPopupmenu.addMenuItem('-')
//	var vMenuItem4 = vPopupmenu.addMenuItem('i18n:1.archive1', startAction, 'media:///folder_into.png')
//	var vMenuItem5 = vPopupmenu.addMenuItem('i18n:1.delete', startAction, 'media:///delete2_16.png')	

	vMenuItem1.selected = true

	// To transfer the right element and formname triggers you have to set them as arguments
	vMenuItem1.methodArguments = [1];
	vMenuItem2.methodArguments = [2]
//	vMenuItem4.methodArguments = [3]
//	vMenuItem5.methodArguments = [4]

	// Get the x coordinate of the element relative to the screen...
	var button = elements[vEvent.getElementName()]
	
	// calculate the new x coordinate for the dialog.
	var x = plugins.it2be_tools.getScreenX(button) - button.getLocationX();

	// calculate the new y coordinate for the dialog.
	var y = plugins.it2be_tools.getScreenY(button) + button.getHeight() - button.getLocationY();

	var vSource = vEvent.getSource()
	if (vSource != null) {
		vPopupmenu.show(x,y);
		
	}

}

I heard a rumor that a solution for this is in the works… ;)

Maak me gek! :lol:

I am happy to announce the immediate availability of the MousePointer plugin (my first Servoy plugin! :D )
A big thank you to Patrick Talbot for answering my questions and for signing the jar for me.

You can find the plugin (and demo solution) on ServoyForge.

Note: this plugin is for Smart Client only.

Enjoy!

where is the code?

https://www.servoyforge.net/projects/mo … repository

i can’t find it…

It’s hidden! (on my harddrive) ;)

Will push it out today.

Aaaaaand it’s on the site.

Enjoy!

Okay, I cheered too soon.
In a form that is scrolled down the position is off, I guess that was what Harjo meant with ‘when used in a smaller window’.

Working on a solution…

It seems the solution needs to come from servoy.
I filed a feature request. Please add your vote to the feature request if you want this too.

https://support.servoy.com/browse/SVY-1623

(Voting needs to be done ON that issue, not in this forum thread)

Patrick Talbot strikes again!
He created a patch for the window plugin (for the 5.2, 6.0 and 6.1 branch!) and it works great (I just tested this)!

Go vote for it (on the ticket) to have Servoy actually implement this patch !
It will in fact nullify my MousePointer plugin, all you will need is this new Window plugin version (when implemented by Servoy).

Do note the fix is for Smart Client only.