views:

51

answers:

4

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

A: 

Works fine for me when using the demo code the the How to Use Layered Panes tutorial.

Based on the 3 lines of code the only difference I can see from the tutorial is that you are using a layout manager.

Compare your code with the tutorial to find other differences.

camickr
A: 

Have you tried taking the first working code, but placing the m_mediaPanel on level 1? This probably won't work either. I think this is due to the fact that the panel that is on top determines the cursor. On level 0 the layered pane itself can determine this.

Marc
+1  A: 

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.

jfpoilpret
A: 

I am getting the same problem on linux 64 bit red hat.

sumit