我所说的输入元素是指 JSpinners 和 JComboxBoxes 之类的东西。我的 glasspane 传递了一个 JPanel,其中包含 JSpinners、JComboBoxes 和大部分 JLabels。玻璃窗格附加了一个 MouseListener。令人惊讶的是,当鼠标光标离开输入元素并悬停在 JPanel 的其他部分或空白空间上时,会调用 mouseEntered!这是正常行为吗?为了 Glasspane 的目的,如何让输入元素被视为 JPanel 的一部分?
这是我的 UI 的屏幕截图,其中包含输入元素和 jLabels。

这是一段代码示例:
import javax.swing.*;
public class DialogTest {
    public DialogTest() {
        JPanel dialogPanel = new JPanel();
        SpinnerModel edgeModel = new SpinnerNumberModel(1, 1, 9, 1);
        JSpinner edgeSpn = new JSpinner(edgeModel);
        dialogPanel.add(edgeSpn);
        JDialog initialDialog = new JDialog(new JFrame(), "Test", true);
        initialDialog.setContentPane(dialogPanel);
        initialDialog.pack();
        glass = new GlassComponent(dialogPanel);
        initialDialog.setGlassPane(glass);
        glass.setOpaque(false);
        glass.setVisible(true);
    initialDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    initialDialog.setVisible(true);
    }
}
public class GlassComponent implements MouseListener {
   JPanel c;
   public GlassComponent(JPanel c) {
       this.c = c;
       this.c.addMouseListener(this);
   }
   ...
   public mouseEntered(MouseEvent e) {
       System.out.println("Entered JPanel");
   }    
}
作为解释,我的目标是最终使用 GlassPane 来阻止那些标有禁止标志的元素的输入。但是,考虑到分配给 dialogPanel 的 mouseListener 在离开输入元素时似乎会生成新事件,我可能会遇到一些困难。