Hello All
I need to know the actual mouse click position when mouse is clicked on a label.
But the event parameter is not returning the correct value.
event.getX : 0 and event.getY(): 0
JSEvent(type = action, source = LABEL,[name:lbl_test,x:620,y:20,width:180,height:110,label:], formName = form1, elementName = lbl_test, timestamp = Wed May 19 19:11:58 IST 2010,modifiers = 16,x =0,y = 0,data = null)
Am I missing something to get these values. I am using Servoy 5.1.2.
Thanks in advance.
pradiptab:
Hello All
I need to know the actual mouse click position when mouse is clicked on a label.
But the event parameter is not returning the correct value.
event.getX : 0 and event.getY(): 0
JSEvent(type = action, source = LABEL,[name:lbl_test,x:620,y:20,width:180,height:110,label:], formName = form1, elementName = lbl_test, timestamp = Wed May 19 19:11:58 IST 2010,modifiers = 16,x =0,y = 0,data = null)
Am I missing something to get these values. I am using Servoy 5.1.2.
Thanks in advance.
Coordinates are relative, not absolute, this means point (0,0) “in” the label. Do you really need the absolute coordinates ?
Yes I need the absolute Coordinates.
Thats why I have not set any anchor property except top and left.
The label is having fixed height and width regardless of the form size.
As the name suggest getX() and getY(), that should return the coordinates.
Or is there any other way???
pradiptab:
Yes I need the absolute Coordinates.
Thats why I have not set any anchor property except top and left.
The label is having fixed height and width regardless of the form size.
As the name suggest getX() and getY(), that should return the coordinates.
Or is there any other way???
Why do you need the absolute coordinates ? You can calculate them, but may not be easy.
This is very necessary in my Calendar application where I cannot create unnecessary hundreds of elements for each date and time.
I need the mouse click position from which I can actually calculate the date and time easily.
Is it a issue in Servoy 5.1.2.
pradiptab:
This is very necessary in my Calendar application where I cannot create unnecessary hundreds of elements for each date and time.
I need the mouse click position from which I can actually calculate the date and time easily.
Is it a issue in Servoy 5.1.2.
ok, but you have the source element, there must be something in the source to determine date and time (for example location of the element). We just pass the coordinates from java event.
From the release notes http://forum.servoy.com/viewtopic.php?f=16&p=68489
-getX(): returns the x coordinateof the cursor at the moment of the event trigger
-getY(): returns the y coordinateof the cursor at the moment of the event trigger
I currently can’t find a way to make this work and was wondering if anyone has had any success with this. In the handful of scenarios I have attempted (forms, buttons, labels) the coordinates of 0,0 are returned no matter where or what you click. We have a use for this type of described functionality though as a relative position it is a bit less useful.
Absolute coordinates are useful on table/list views where position relative to an element is useless for finding absolute x/y on the screen/window.
Unless this is intended to spit out the position relative to where the cursor is when the event is triggered (always 0,0
), this might be a bug.
which kind of events are you talking about?
onaction?
I’ve been trying it with onAction but also wondered about it with the onRecordSelection as well. We are on 5.1.4 but thinking of flipping over to 5.2 if that would help. We want to release a 5 in the next month but this isn’t an earth-shattering bug, at the moment it would just fix a problem we have never been able to take care of.
I tried it without success in 5.2 rc2 as well.
I use this to get my mouseposition in list views:
var mouse = java.awt.MouseInfo.getPointerInfo().getLocation();
var x = mouse.x;
var y = mouse.y;
onAction of a button doesnt have mouse positions.
Because a button doesnt have to be pressed by a mouse… It can be just keyboard… In java the ActionEvent of an actionPerformend method only has modifiers (so is the ALT key pressed) not the mouse position (if it has been triggered by a mouse)
onRecordSelection is a form event but not a ui event. There is the same a a SelectionEvent in a java JList or JTable… Those also dont have mouse positions.
The events that really set mouse stuff are only events that really are mouse triggered events like getRightClick should set it (but i do see that also those in 5.2 dont work)
jcompagner:
onAction of a button doesnt have mouse positions.
Because a button doesnt have to be pressed by a mouse… It can be just keyboard… In java the ActionEvent of an actionPerformend method only has modifiers (so is the ALT key pressed) not the mouse position (if it has been triggered by a mouse)
onRecordSelection is a form event but not a ui event. There is the same a a SelectionEvent in a java JList or JTable… Those also dont have mouse positions.
The events that really set mouse stuff are only events that really are mouse triggered events like getRightClick should set it (but i do see that also those in 5.2 dont work)
The code I posted above you does output the mouse x and y when I use onAction on a button.
yes that is true, we could even do that for you by filling the x and y with that same code.
But then an onaction could be triggered by keyboard and the mouse position doesn’t reflect really anything because the mouse was not responsible for that event.
Same is true if you would use that code in a onRecordSelection event… selection can be triggered by anything doesnt have to be a mouse click at all…
So what would then X and Y mean?
jcompagner:
yes that is true, we could even do that for you by filling the x and y with that same code.
But then an onaction could be triggered by keyboard and the mouse position doesn’t reflect really anything because the mouse was not responsible for that event.
Same is true if you would use that code in a onRecordSelection event… selection can be triggered by anything doesnt have to be a mouse click at all…
So what would then X and Y mean?
I thought the question was whether or not you could get the current mouse-position, Grimbert’s code does this. If there is a reason for Servoy not to output the actual mouse position from an event, then don’t add the parameters, that’s just confusing.
If one doesn’t want the behaviour you describe above, then one should make sure that the label cannot be triggered by a keyboard press, so just take it out of the tab-sequence.
I can imagine that for a calendaring solution, you only want to allow mouse triggering
@Grimbert
Does this code give the position in the form, window or the screen ?
It gives the position on the screen.
I use the code as following to get the mouse location on my forms.
var mousePointerInfo = java.awt.MouseInfo.getPointerInfo().getLocation();
var x = mousePointerInfo.x;
var y = mousePointerInfo.y;
var wX = application.getWindowX();
var wY = application.getWindowY();
x = x-wX;
y = (y-wY)-25;
(25 is the height of the titlebar of the form)
I think in general the problem with this code could be timing. If the user clicks somewhere, then moves the mouse (fast) and this logic asks for the current mouse position slightly later, then you get the wrong position. If a mouse position is retrieved via an event, then it really is the mouse position at the time when the event occurred, not a position where the mouse was moved afterwards.