findComponentAt fails with JDialog
Hi. I've been stuck on this for a couple days now- the findComponetAt method of java.awt.Container seems to dislike JDialogs (as well as me). The following:
import java.awt.*;
import java.awt.event.MouseEvent;
import javax.swing.*;
import javax.swing.event.MouseInputAdapter;
publicclass DummyDisplay{
publicstaticvoid main(String[] args){
JFrame frame =new JFrame();
frame.add(new DummyPanel());
frame.pack();
frame.setVisible(true);
JDialog dialog =new JDialog();
dialog.add(new DummyPanel());
dialog.pack();
dialog.setVisible(true);
}
privatestaticclass DummyPanelextends JPanel{
privatestaticfinallong serialVersionUID = 0;
public DummyPanel(){
add(new JLabel("Here's label 1..."), BorderLayout.WEST);
add(new JLabel("Here's label 2..."), BorderLayout.EAST);
addMouseListener(new MouseInputAdapter(){
publicvoid mousePressed(MouseEvent event){
Point loc = event.getPoint();
Component label = DummyPanel.this.findComponentAt(loc.x, loc.y);
System.out.println("Detected: " + label);
}
});
}
}
}
Displays two windows (a JFrame and JDialog). When I click within the JFrame it detects the labels. However, when I click within the JDialog it finds null.
The getComponentAt method behaves properly in this case, but has a nasty habit of occasionally returning invisible components (depending on when the visibility was set). The issue is with version 1.5.0_08 on Ubuntu (Edgy). Any help would be appreciated! -Damian

