I have a problem where my listener does not get all of AWT Events. Or at least I hope so. My another problem is that I couldn't reconstruct the issue on a Snippet of code. :(
What I do is:
Listen to all AWTEvents (only mouse event actually),
mouse press starts a timer,
when the timer is done and the LMB is still pressed, component at mouse pointer is removed from the hierarchy.
At this point as long as I am still ppressing the LMB i get only MOUSE_EXITED and MOUSE_ENTERED events. No move, drag or even mouse released events.
As soon as I release the mouse button everything returns to normal.
Any suggestions what could cause the problem?
@Edit: code example updated
package awtbug;
import java.awt.AWTEvent;
import java.awt.Toolkit;
import java.awt.event.AWTEventListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.Timer;
@SuppressWarnings("serial")
public class MyAWTBug extends JFrame{
public static void main(String[] args) {
new MyAWTBug();
}
public MyAWTBug() {
setSize(300, 300);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.getContentPane().add(new AWTListenerPanel());
}
private class AWTListenerPanel extends JPanel implements AWTEventListener {
JPanel somePanel = new JPanel();
public AWTListenerPanel() {
Toolkit.getDefaultToolkit().addAWTEventListener(this, Long.MAX_VALUE);
this.add(somePanel);
}
@Override
public void eventDispatched(AWTEvent event) {
System.out.println("-----------------------");
System.out.println(event);
if (event instanceof MouseEvent) {
if (event.getID() == MouseEvent.MOUSE_PRESSED) {
Timer timer = new Timer(100, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
modifyTree();
}
});
timer.setRepeats(false);
timer.restart();
}
}
}
private void modifyTree() {
getContentPane().remove(somePanel);
getContentPane().add(somePanel);
System.err.println("stuff done");
}
}
}
@Edit 2: I could narrow it down to the
outsideComp.remove(insideComp);
as soon as I do this, events stop coming...