Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to set mouse cursor JLayeredPane

I'm running into a problem that I can't seem to figure out nor find the answer anywhere on the web.

I've got a JLayeredPane and when it only has one child Panel I am able to correctly set the cursor using setCursor(). The cursor shows up and everything is fine. But when I add an additional JPanel into the JLayeredPane the cursor no longer shows up

for example this works:

m_layeredPane = new JLayeredPane();
m_layeredPane.setLayout(new WBLayoutManager());
m_layeredPane.add(m_mediaPanel, new Integer(0));
// m_layeredPane.add(m_whiteboardPanel, new Integer(1));

m_layeredPane.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); // WORKS

but this doesn't:

m_layeredPane = new JLayeredPane();
m_layeredPane.setLayout(new WBLayoutManager());
m_layeredPane.add(m_mediaPanel, new Integer(0));
m_layeredPane.add(m_whiteboardPanel, new Integer(1));

m_layeredPane.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); // FAILS

Anyone know how i can get custom cursors working within a JLayeredPane

like image 816
bradforj287 Avatar asked Nov 02 '25 14:11

bradforj287


1 Answers

If you take a look at javax.swing.JLayeredPane source code, you will see its constructor defined like that:

public JLayeredPane() {
    setLayout(null);
}

which clearly indicates that it needs to handle components layout by itself. Hence you can guess (although it is not documented, I would consider it a documentation bug) that you should not change the layout of JLayeredPane.

like image 186
jfpoilpret Avatar answered Nov 04 '25 07:11

jfpoilpret



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!