title: Java Custom Cursor sometimes shows as default on MacOS
body: <p>On the following code sample, the cursor will change to whatever 32x32 image you place at "icon/cursor/" with the name "pointer-measure.png".</p>
  
  <p>The problem is: on MacOS, if you keep the mouse moving in and out of the frame, sometimes the custom image is shown, and other times is the default cursor that appears. This behavior I observed only on MacOS - if I run the same code on Windows, it shows the custom cursor every time.</p>
  
  <p>Anyone had the same issue? Is there a workaround for that?</p>
  
  <pre><code>public class JavaApplication2 {
  
  public static final Cursor MOVE_CURSOR = getCustomCursor("pointer-measure.png", "bt-drawing", 15, 15);
  
  public static void main(String[] args) {
      JFrame  frame = new JFrame();
      frame.setSize(300, 300);
  
      JPanel panel = new JPanel();
      panel.setBorder(BorderFactory.createLineBorder(Color.red));
      panel.setCursor(MOVE_CURSOR);
  
      frame.add(panel);
      frame.setVisible(true);
  }
  
  public static Cursor getCustomCursor(String filename, String cursorName, int hotSpotX, int hotSpotY) {
      Toolkit defaultToolkit = Toolkit.getDefaultToolkit();
      ImageIcon icon = new ImageIcon(JavaApplication2.class.getResource("icon/cursor/" + filename));
      Dimension bestCursorSize = defaultToolkit.getBestCursorSize(icon.getIconWidth(), icon.getIconHeight());
      Point hotSpot = new Point((hotSpotX * bestCursorSize.width) / icon.getIconWidth(),
          (hotSpotY * bestCursorSize.height) / icon.getIconHeight());
      return defaultToolkit.createCustomCursor(icon.getImage(), hotSpot, cursorName);
  }
  
  }
  </code></pre>
  
  <p>Obs: I was running on MacOS Sierra and Windows 10.</p>