Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic How to get the right X,Y for mouse event , popup menu. (Read 1945 times)
Bruno Dufour
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 16
Joined: Jul 28th, 2022
How to get the right X,Y for mouse event , popup menu.
Aug 15th, 2022 at 9:08pm
Print Post  

Need to display my popup on the selected appointment (see attached image).

What I understand is getSource() returns the invoker (the Calendar object).
And the X and Y are from the invoker.

I am using show (Invoker, X, Y ) method from JPopupMenu.

.. and As you can see in the attached file, I get the wrong position.

Do you have a code example how to get the right mouse position in the Screen coordinates..??


This is my code...

protected void onItemClick(ItemMouseEvent e) {

        Object lObj = e.getSource();
        int lX = e.getX();
        int lY = e.getY();

        Item lItem = e.getItem();
        Point p = new Point(lX, lY);
        System.out.println("X:" + p.x + " Y:" + p.y);


        // Operation && right click
        if (lItem instanceof cSimpleOperation && e.getButton() == MouseEvent.BUTTON3) {
          
               javax.swing.SwingUtilities.convertPointToScreen(p, (JComponent) lObj);

               cSCOperation lOPModel = ((cSimpleOperation) lItem).mGetModel();
               cADO[] lADO = {lOPModel.mGetJobOrderID().mGetADO()};

             cPopupMenu lMenu = cMenuFactory.mGetPopupMenu(lADO, null, null, "x", null);
              lMenu.show( (JComponent) lObj, p.x, p.y);

        }
}
  

bug2.png ( 222 KB | 175 Downloads )
bug2.png
Back to top
 
IP Logged
 
Slavcho
God Member
*****
Offline


tech.support

Posts: 3419
Joined: Oct 19th, 2005
Re: How to get the right X,Y for mouse event , popup menu.
Reply #1 - Aug 16th, 2022 at 7:34am
Print Post  
These coordinates are local for the clicked item. You could add Calendar.getItemBounds' location to them to get ones relative to the calendar control.

There's the samples/Clipboard example showing context menu. It gets mouse screen position directly through java.awt.MouseInfo.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Bruno Dufour
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 16
Joined: Jul 28th, 2022
Re: How to get the right X,Y for mouse event , popup menu.
Reply #2 - Aug 16th, 2022 at 11:38am
Print Post  
Thanks!

It works !
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint