1

我正在尝试使用 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) 中绘制一个光标时 - 什么也没有发生。我究竟做错了什么?

4

0 回答 0