MouseListener MouseExited event does not work in an unshared dialog box with the frame disabled

I have some problems with the mouseExited event. I have one undecorated JDialog with MouseListener, this JDialog is half above one disabled JFrame. The mouseExited event is triggered by the mouse exit dialog and goes to the desktop, but if the mouse leaves the dialog and goes to the disabled frame, the event will not be fired. This only happens if the frame is off. And I don’t know why .. Can someone help me?

Here is an 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); } } 
+5
source share
1 answer

Component # setEnabled (boolean) (Java SE 8 platform)
Note: Disabling the heavyweight container prevents all components in this container from receiving any input events. But disconnecting a lightweight container only affects that container.

JFrame is a heavyweight (top level) component, so I consider this behavior to be a specification.

+1
source

Source: https://habr.com/ru/post/1274583/


All Articles