I've created a grid of Rectangle objects and added them to a Pane. Each rectangle has a mouse event listener attached to it which get triggered by the MouseEvent.Entered trigger. The handler simply changes the colour of the rectangle when the user moves the mouse over the rectangle. The issue is that the trigger seems to have a considerable delay before it gets executed. Any ideas how to speed this up so its realtime with the mouse?
I've uploaded a recording here: https://screencast-o-matic.com/watch/cFQI0lqdHe
public class WarehouseMap extends Pane {
private int xSpaces = 200;
private int ySpaces = 100;
private ArrayList<Rectangle> gridReferences = new ArrayList<Rectangle> ();
public WarehouseMap() {
setWidth(2000);
setHeight(1000);
initGrid();
}
public void initGrid() {
double rectWidth = getWidth() / xSpaces;
double rectHeight = getHeight() / ySpaces;
for(int x=0; x<xSpaces; x++) {
for(int y=0; y<ySpaces; y++) {
Rectangle gr = new Rectangle(x*rectWidth, y*rectHeight, rectWidth, rectHeight);
gr.setStroke(Color.GRAY);
gr.setFill(Color.TRANSPARENT);
gr.setStrokeWidth(1);
gr.addEventHandler(MouseEvent.MOUSE_ENTERED, new EventHandler<MouseEvent> () {
@Override
public void handle(MouseEvent event) {
gr.setFill(Color.DARKGRAY);
}
});
gr.addEventHandler(MouseEvent.MOUSE_EXITED, new EventHandler<MouseEvent> () {
@Override
public void handle(MouseEvent event) {
gr.setFill(Color.TRANSPARENT);
}
});
gridReferences.add(gr);
this.getChildren().add(gr);
}
}
}
}

