[英]MouseListener event MouseExited doesn't work on undecorated dialog over disabled frame
我在mouseExited事件上遇到了一些麻煩。 我有一個帶有MouseListener的未修飾的JDialog,這個JDialog是一個禁用的JFrame的一半。 當鼠標退出對話框並在桌面上運行時會觸發mouseExited事件,但是如果鼠標退出對話框並且檢查禁用的框架,則不會觸發事件。 僅在禁用幀時才會發生這種情況。 我不知道為什么..有人可以幫助我嗎?
這是一個快速的例子:
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)
注意: 禁用重量級容器會阻止此容器中的所有組件接收任何輸入事件。 但禁用輕量級容器只會影響此容器。
JFrame
是一個重量級(頂級)組件,所以我認為這種行為是規范。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.