Javafx - Determine position of cursor on right click relative to gridpane
<p>I have a 40x40 gridpane, displaying a map. Currently, i have the following methods listening for a right click:</p>

<pre><code>    //detect right click + display menu, select if you want to place item 1 or item 2
    final ContextMenu cm = new ContextMenu();
    cm.addEventFilter(MouseEvent.MOUSE_RELEASED, new EventHandler&lt;MouseEvent&gt;() 
    {
        @Override
        public void handle(MouseEvent event) 
        {
            if (event.getButton() == MouseButton.SECONDARY) 
                event.consume();

        }
    });
    cm.setOnAction(new EventHandler&lt;ActionEvent&gt;() {
        @Override
        public void handle(ActionEvent event) {
            System.out.println("Following item selected: "+
                    ((MenuItem)event.getTarget()).getText());
        }
    });
    //two placeable items
    MenuItem item1Place = new MenuItem("Item 1");
    MenuItem item2Place = new MenuItem("Item 2");
    cm.getItems().addAll(item1Place, item2Place);

    primaryStage.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler&lt;MouseEvent&gt;() 
    {
        @Override
        public void handle(MouseEvent e)
        {
            if (e.getButton() == MouseButton.SECONDARY) 
            {
              cm.show(primaryStage, e.getScreenX(), e.getScreenY());
            } 
        }
    });
</code></pre>

<p>What I'd like to implement is the following:</p>

<blockquote>
  <p>If a menu item is selected after a right click, i'd like to save
  the position of the right click in a variable  <br>e.g. [32,12] if
  right click was 32 blocks of the gridpane across, and 12 blocks up.</p>
</blockquote>

<p><br>Any suggestions on how to go about doing this? 
<br>Thanks in advance</p>

<pre><code>// first edit code entered below. I realise the indentation is very off however fixing it seemed to turn it back to plain text
placeItem1.setOnAction(evt -&gt; System.out.println("Item 1 placed ["+col+", "+row+"]"));
                placeItem2.setOnAction(evt -&gt; System.out.println(Item 2 placed["+col+", "+row+"]"));
                menu.show(cell, e.getScreenX(), e.getScreenY());
            });
            root.add(cell, x, y);
</code></pre>