JDK-4084431 : removing lightweight comp causes drag events to disappear
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.1.3,1.1.8_003,1.3.0
  • Priority: P4
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: windows_95,windows_nt
  • CPU: x86
  • Submitted: 1997-10-07
  • Updated: 2010-11-17
  • Resolved: 2010-11-17
Related Reports
Relates :  
Relates :  
Description
Name: paC48320			Date: 10/07/97


/*This is a resubmission of a bug report as requested
by Peter J. Allenbach OPCOM Consuntant 9.19.97.
Below I provide
an example of code which reproduces the bug.

if you run the program and then press and drag the
mouse over the red lightweight component you will
see that once the component is removed subsequent
drag events are not recieved by either the Frame 
or the lightweight. If you change 'Component'
to 'Canvas' and make the component heavyweight
you will see the drag events are recieved by
the Frame after the removal of the Canvas.*/
//***********************************************
import java.awt.*; import java.awt.event.*;
class Test extends Frame{
	Test handle;
   Test(){enableEvents(AWTEvent.MOUSE_MOTION_EVENT_MASK);
	handle=this; setLayout(null); LW lw=new LW(); add(lw); lw.setBounds(0,0,50,50);
	setSize(100,100); setVisible(true);
   }
   public void processMouseMotionEvent(MouseEvent me){
 	if(me.getID()==MouseEvent.MOUSE_DRAGGED)System.out.println("Test Drag event");
	super.processMouseMotionEvent(me);
  }
 class LW extends Component{//inner class
   LW(){enableEvents(AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK);}
   public void processMouseEvent(MouseEvent me){
	if(me.getID()==MouseEvent.MOUSE_PRESSED){
	handle.remove(this); handle.repaint(); System.out.println("LW removed");}
	super.processMouseEvent(me);
   }
   public void processMouseMotionEvent(MouseEvent me){
 	if(me.getID()==MouseEvent.MOUSE_DRAGGED)System.out.println("LW Drag event");
	super.processMouseMotionEvent(me);
  }
   public void update(Graphics G){paint(G);}
   public void paint(Graphics G){
	Dimension dim=getSize();
	G.setColor(Color.red); G.fillRect(0,0,dim.width,dim.height);
   }
 }//end of LW
   public static void main(String args[]){new Test();}
}
//***********************************************
======================================================================

Comments
EVALUATION Toplevel doesn't receive any move or drag event on component removal. Once I initiate the drag again they start to coming.
17-11-2010

WORK AROUND Name: paC48320 Date: 10/07/97 ======================================================================
17-09-2004

EVALUATION 5/27/2000 kevin.ryan@eng -- reproducible on win32 only (1.1.8_003 and 1.3.0-C). Please see Comments section. ===== Seems like a valid bug because lightweight children should behave the same as heavyweight children. Reproducible with merlin-b70 on both Solaris and Windows. david.mendenhall@east 2001-07-12 Still reproducible in merlin-b86 (Solaris & win32) w/ a Swing-based test case: import javax.swing.*; import java.awt.event.*; public class BLWTest implements MouseMotionListener { static JButton b; static JFrame f; static BLWTest mml = new BLWTest(); public BLWTest() {} public static void main(String args[]) { f = new JFrame("BLWTest"); b = new JButton("LW Button"); b.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { System.out.println("JButton removed"); f.getContentPane().remove(b); f.repaint(); } }); f.addMouseMotionListener(mml); b.addMouseMotionListener(mml); f.getContentPane().add(b); f.setSize(200, 200); f.setVisible(true); } public void mouseMoved(MouseEvent e) {} public void mouseDragged(MouseEvent e) { System.out.println("MouseDragged"); } } ###@###.### 2001-11-19 Name: dmR10075 Date: 02/24/2004 Not reproducible on Solaris/Linux with 1.4 and 1.3.1 ###@###.### 2004-2-24 ====================================================================== Name: osR10079 Date: 03/05/2004 The problem is reproducible on all platforms with all jdks up to tiger b41 (current latest build). I think ###@###.### though that it passes because the test doesn't show different between lightweigh and heavyweight. here is a modified test which contains both lightweight and heavyweight components both are removed on mouse pressed. In case of heavyweight component frame receives drag events after that. But for lightweight it doesn't. I think we should try to investigate it in dragonfly. ###@###.### Mar 5, 2004 ====================================================================== Name: aaR10319 Date: 05/28/2004 After MOUSE_PRESSED has occured all consequent mouse events target to the same child component until MOUSE_RELEASED. In this case that is probably incorrect and we should check mouse event target availability for each event. Such check may result either in throwing an exception or changing mouse event target ###@###.### 2004-05-28 ======================================================================
28-05-2004