I have a double matrix for which I construct a heatMap using the HeatMap class ( http://www.mbeckler.org/heatMap/). I use MouseMotionListener to get the mouse position when it is hovered over the image. Since the actual heatmap is smaller than the HeatMap panel, I set coordinate bounds for getting the mouse coordinate position (Previous question for details: MouseListener for HeatMap in Java HeatMap Panel )
The mouse event to track the mouse movement looks like this:
public void mouseMoved(MouseEvent e) {
if(e.getPoint().x >= 31 && e.getPoint().y >= 31 && e.getPoint().x <= intensityMap.getWidth()-31 && e.getPoint().y <= intensityMap.getHeight()-31) {
int maxX = (intensityMap.getWidth() - 31)-31;
int maxY = (intensityMap.getHeight() - 31)-31;
intensityMap.add(coordinates);
coordinates.setText("(x,y) = " + "(" + (e.getPoint().x - 31) + "," + (e.getPoint().y - 31) + ")");
coordinates.revalidate();
coordinates.repaint();
}
}
Now, I want to convert these mouse coordinate positions to the coordinate positions of the double matrix which is used to draw the heatMap. The total number of rows as per the mouse event is 235 and the total columns are 128. The dimensions of the double matrix are 37,32. How can I map the coordinates of the double matrix over the heatMap?
This might be helpful. You need to somehow map your matrix with JPanel Object.