Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

i've got some trouble with the mouseExited event. I have one undecorated JDialog with a MouseListener, this JDialog is half over one disabled 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. 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);
    }
}
like image 458
Ap0k Avatar asked Nov 07 '22 12:11

Ap0k


1 Answers

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.

like image 115
aterai Avatar answered Nov 14 '22 22:11

aterai