简体   繁体   English

MouseListener事件MouseExited对禁用帧上的未修饰对话框不起作用

[英]MouseListener event MouseExited doesn't work on undecorated dialog over disabled frame

i've got some trouble with the mouseExited event. 我在mouseExited事件上遇到了一些麻烦。 I have one undecorated JDialog with a MouseListener, this JDialog is half over one disabled JFrame. 我有一个带有MouseListener的未修饰的JDialog,这个JDialog是一个禁用的JFrame的一半。 The mouseExited event is fired when the mouse exit dialog and go on the desktop, but if the mouse exit dialog and go over the disabled frame the event isn't fired. 当鼠标退出对话框并在桌面上运行时会触发mouseExited事件,但是如果鼠标退出对话框并且检查禁用的框架,则不会触发事件。 This happens only if the frame is disabled. 仅在禁用帧时才会发生这种情况。 And i don't know why.. Someone can help me? 我不知道为什么..有人可以帮助我吗?

Here is a fast example: 这是一个快速的例子:

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class MouseListenerTest {
    public static void main(String a[]) {
        System.out.println("java.version: " + System.getProperty("java.version"));
        JFrame ownerFrame = new JFrame("Hello i am the owner frame :)");
        ownerFrame.setBounds(100,100,500,500);
        ownerFrame.setVisible(true);
        ownerFrame.setEnabled(false);
        JDialog topDialog = new JDialog(ownerFrame, "Hello i am the top dialog");
        topDialog.getContentPane().setBackground(Color.YELLOW);
        topDialog.setUndecorated(true);
        final JLabel xLabel = new JLabel("I am OUT");
        xLabel.setHorizontalAlignment(JLabel.CENTER);
        topDialog.getContentPane().add(xLabel, BorderLayout.CENTER);
        topDialog.addMouseListener(new MouseAdapter(){
            @Override
            public void mouseEntered(MouseEvent e) {
                System.out.println("I am IN");
                xLabel.setText("I am IN");
            }

            @Override
            public void mouseExited(MouseEvent e) {
                System.out.println("I am OUT");
                xLabel.setText("I am OUT");
            }});
        topDialog.setBounds(500,200,200,200);
        topDialog.setVisible(true);
    }
}

Component#setEnabled(boolean) (Java Platform SE 8 ) Component#setEnabled(boolean)(Java Platform SE 8)
Note: Disabling a heavyweight container prevents all components in this container from receiving any input events. 注意: 禁用重量级容器会阻止此容器中的所有组件接收任何输入事件。 But disabling a lightweight container affects only this container. 但禁用轻量级容器只会影响此容器。

JFrame is a heavyweight (top level) component, so I think that this behavior is specification. JFrame是一个重量级(顶级)组件,所以我认为这种行为是规范。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM