我正在尝试使用JLayeredPane创建一个Kinect驱动的UI。 UI由4个JPanel组成。在这4个JPanel的顶部,我想画一个光标来显示用户的光标。使用JLayeredPane时,我无法移动光标。应该在这4个JPanel的顶部绘制光标,以便我放置JPanel,它将光标绘制在更高层。我的代码如下所示:
mainFrame = new JFrame();
mainFrame.setSize(WIDTH, HEIGHT);
mainFrame.setTitle("Kinect module");
mainFrame.setMinimumSize(new Dimension(1200, 800));
mainFrame.setVisible(true);
controlPanel = new JPanel();
controlPanel.setPreferredSize(new Dimension(1180, 110));
Color controlPanelBcg = new Color(255, 64, 16);
controlPanel.setBackground(controlPanelBcg);
propertiesPanel = new JPanel();
propertiesPanel.setPreferredSize(new Dimension(210, 540));
Color propertiesPanelBcg = new Color(16, 255, 64);
propertiesPanel.setBackground(propertiesPanelBcg);
statusPanel = new JPanel();
statusPanel.setPreferredSize(new Dimension(1180, 110));
Color statusPanelBcg = new Color(64, 16, 255);
statusPanel.setBackground(statusPanelBcg);
statusPanel.setPreferredSize(new Dimension(1180, 110));
displayPanel = displayManager.getJPanel(DisplayType.DEFAULT);
displayPanel.setPreferredSize(new Dimension(960, 540));
cursorPanel = new CursorPanel(context, sessMan);
cursorPanel.setVisible(true);
cursorPanel.setSize(1200, 800);
cursorPanel.setOpaque(false);
layeredPane = new JLayeredPane();
layeredPane.setPreferredSize(new Dimension(1200, 820));
layeredPane.setLayout(new FlowLayout(FlowLayout.LEADING, 5, 5));
layeredPane.add(controlPanel, JLayeredPane.DEFAULT_LAYER);
layeredPane.add(displayPanel, JLayeredPane.DEFAULT_LAYER);
layeredPane.add(propertiesPanel, JLayeredPane.DEFAULT_LAYER);
layeredPane.add(statusPanel, JLayeredPane.DEFAULT_LAYER);
layeredPane.add(cursorPanel, JLayeredPane.MODAL_LAYER);
mainFrame.getContentPane().add(layeredPane);
mainFrame.pack();
布局就像我想要的那样。但是当我想在cursorPanel的方法paintComponent(Graphics g)中绘制光标时 - 没有任何反应。我做错了什么?