title: Java Swing - Use the cursor of a sibling component instead of the parent's?
body: <p>By default, if a swing component doesn't have a cursor set, it uses the cursor of it's parent.</p>
  <p>Is it possible to change so that the component uses the cursor of a sibling component instead?</p>
  <p>In my application I have a JLayeredPane, with two overlapping JPanels inside of it. One is a transparent overlay on top, the other is a solid regular panel underneath. I would like the cursor in the overlay to be the one corresponding to the solid regular JPanel (the sibling). However, the cursor used by default is the cursor of the JLayeredPane (the parent).</p>
  <p>How do I make the overlay uses the cursor of the solid JPanel?</p>
  <p>Example:</p>
  <pre class="lang-java prettyprint-override"><code>import javax.swing.*;
  import java.awt.*;
  
  public class TestCursor {
      public static void main(String[] args)
      {
          SwingUtilities.invokeLater(() -&gt; {
              Dimension dim = new Dimension(400, 400);
  
              // The JFrame holding everything.
              JFrame frame = new JFrame();
              frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
              frame.setVisible(true);
  
              // The JLayeredPane.
              JLayeredPane layeredPane = new JLayeredPane();
              layeredPane.setPreferredSize(dim);
              frame.add(layeredPane);
  
              // The panel with the color and hand cursor.
              JPanel panel = new JPanel();
              panel.setBackground(Color.BLUE);
              panel.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
              panel.setSize(dim);
  
              // The invisible panel
              JPanel transpPanel = new JPanel();
              transpPanel.setOpaque(false);
              transpPanel.setBackground(new Color(0,0,0,0));
              transpPanel.setSize(dim);
  
              // Add the two panels. The cursor is not the hand cursor.
              layeredPane.add(transpPanel, -1);
              layeredPane.add(panel, -1);
  
              frame.pack();
          });
      }
  }
  
  </code></pre>