JDK-4478302 : Moving a JWindow does not generate corresponding event AND prob w/ setLocation
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.3.1,1.4.0
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS: solaris_2.6
  • CPU: sparc
  • Submitted: 2001-07-10
  • Updated: 2002-05-16
  • Resolved: 2001-10-30
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other Other
1.3.1_02 02Fixed 1.4.0Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Description
Moving a JWindow does NOT generate a corresponding event. setLocation method
does not work consistently with JWindow. These 2 problems are not seen with 
JFrame. This problem is observed in jdk 1.3.1 and in jdk 1.4 beta (setLocation
method however seem to work fine in jdk 1.4 beta).

JWindow is used in this production application not to have the WM decorations,
for various reasons. This application (like a CDE front panel), acts as a
control center, launching other applications. This application needs to appear
as being part of the screen, as something that controls the entire desktop.
This application needs to be visible and at a set location at all times
(and cannot give the appearance that it can be moved, iconified, maximized,
etc). Unfortunately, users still can use dtwm modifiers (Alt-F7, Alt-F9, etc)
to move, iconify, etc JWindow based GUI. There is a need to negate these users'
behavior, but unfortunately this bug prevents doing that.

setLocation() does not work consistently, the JWindow is displayed at different
locations. In the case of Jwindow move, it appears that the Java Virtual Machine 
never receives notification that the window has moved. No event is sent. 
Therefore, the window "thinks" it's still at the initial position 0,0.  
This appears to be a problem between the C libraries of Java and Solaris 
(i.e., a Java bug).

We used java.awt.Frame.setUndecorated(true), as mentioned (commented out) in the
supplied sample code (new feature in jdk 1.4 beta). But unfortunatley, we 
encountered other problems (in process of filing bug reports w.r.t. jdk 1.4 beta).


Code Examples:
A.  TestIconifyMoveFrame.java
    This code example uses a JFrame and shows the correct (expected) behaviors:
1.  Moving the JFrame (pressing Alt-F7 with frame in focus, moving mouse to 
    new location and clicking to complete move) generates a ComponentEvent and 
    calls the componentMoved() method.
2.  setLocation method called from within the code works consistently.

B.  TestIconifyMoveWindow.java
    This code example uses a JWindow and does NOT exhibit the correct
    (expected) behaviors:
1.  Moving the JWindow (pressing Alt-F7 with window in focus, moving mouse
    to new location and clicking to complete move) does NOT generate a
    ComponentEvent!
2.  setLocation() method does not work consistently, when called within
    the code (or if it where to be called from the ComponentEvent handler).


TestIconifyMoveFrame.java
==========================
import java.awt.Point;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;


public class TestIconifyMoveFrame extends JFrame
{
    public static void main(String[] args)
    {
	final Point p = new Point(0, 0);

	final JFrame f = new JFrame("Test Frame");

	f.addComponentListener(new ComponentAdapter()
	    {
		public void componentMoved(ComponentEvent e)
		{
		    System.out.println("Component moved to " +
				       f.getLocation());

		    System.out.println("Moving component to " +
				       p);

		    f.setLocation(p);

		    System.out.println("Component now located at " +
				       f.getLocation());

		} // end componentMoved()

	    } // end inner class
			       );

	f.addWindowListener(new WindowAdapter()
	    {
		public void windowClosing(WindowEvent e)
		{
		    System.exit(1);

		} // end windowClosing()

		public void windowIconified(WindowEvent e)
		{
		    System.out.println("Window iconified.  Attempting to deiconify.");

		    f.setState(JFrame.NORMAL);

		    f.show();

		    System.out.println("Window deiconified.");

		} // end windowIconified()

	    } // end inner class
			    );

	
	//  setUndecorated is a new feature in jdk 1.4 beta
	//	f.setUndecorated(true);

	f.setSize(50, 50);

	f.show();

	System.out.println("Init: moving component to " +
			   p);

	f.setLocation(p);

	System.out.println("Init: component now located at " +
			   f.getLocation());

    } // end main()

} // end TestIconifyMoveFrame




TestIconifyMoveWindow.java
==========================
import java.awt.Point;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.JWindow;


public class TestIconifyMoveWindow extends JWindow
{
    public static void main(String[] args)
    {
	final Point p = new Point(0, 0);

	final JWindow w = new JWindow();

	w.addComponentListener(new ComponentAdapter()
	    {
		public void componentMoved(ComponentEvent e)
		{
		    System.out.println("Component moved to " +
				       w.getLocation());

		    System.out.println("Moving component to " +
				       p);

		    w.setLocation(p);

		    System.out.println("Component now located at " +
				       w.getLocation());

		} // end componentMoved()

	    } // end inner class
			       );

	w.addWindowListener(new WindowAdapter()
	    {
		public void windowClosing(WindowEvent e)
		{
		    System.exit(1);

		} // end windowClosing()

		public void windowIconified(WindowEvent e)
		{
		    System.out.println("Window iconified.  Attempting to deiconify.");

		    // NO METHOD EXISTS IN JWINDOW TO DO THIS!!!
		    //		    w.setState(JFrame.ICONIFIED);

		    w.show();

		    System.out.println("Window deiconified.");

		} // end windowIconified()

	    } // end inner class
			    );

	w.setSize(50, 50);

	w.show();

	System.out.println("Init: moving component to " +
			   p);

	w.setLocation(p);

	System.out.println("Init: component now located at " +
			   w.getLocation());

    } // end main()

} // end TestIconifyMoveWindow


Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: 1.3.1_02 merlin-rc1 FIXED IN: 1.3.1_02 merlin-rc1 INTEGRATED IN: 1.3.1_02 merlin-rc1
14-06-2004

PUBLIC COMMENTS Moving a JWindow does NOT generate a corresponding event. setLocation method does not work consistently with JWindow. These 2 problems are not seen with JFrame. This problem is observed in jdk 1.3.1 and in jdk 1.4 beta (setLocation method however seem to work fine in jdk 1.4 beta). setLocation() does not work consistently, the JWindow is displayed at different locations. In the case of Jwindow move, it appears that the Java Virtual Machine never receives notification that the window has moved. No event is sent. Therefore, the window "thinks" it's still at the initial position 0,0. This appears to be a problem between the C libraries of Java and Solaris (i.e., a Java bug).
10-06-2004

SUGGESTED FIX Follwing is the suggested fix: ------- awt_TopLevel.c ------- *** /tmp/sccs.Pvaign Fri Sep 21 15:43:32 2001 --- awt_TopLevel.c Fri Sep 21 14:58:56 2001 *************** *** 2006,2012 **** if (wdata->reparented == 0 && wdata->isShowing && ! runningWM != NO_WM ) break; target = (*env)->GetObjectField(env, this, mComponentPeerIDs.target); --- 2006,2013 ---- if (wdata->reparented == 0 && wdata->isShowing && ! runningWM != NO_WM && ! wdata->decor != AWT_NO_DECOR) break; target = (*env)->GetObjectField(env, this, mComponentPeerIDs.target); ------- MWindowPeer.java ------- *** /tmp/sccs.9daain Fri Sep 21 15:52:48 2001 --- MWindowPeer.java Fri Sep 21 14:51:15 2001 *************** *** 195,201 **** } public void handleMoved(int x, int y) { ! // postEvent(new ComponentEvent(target, ComponentEvent.COMPONENT_MOVED)); } // NOTE: This method may be called by privileged threads. // DO NOT INVOKE CLIENT CODE ON THIS THREAD! --- 195,201 ---- } public void handleMoved(int x, int y) { ! postEvent(new ComponentEvent(target, ComponentEvent.COMPONENT_MOVED)); } // NOTE: This method may be called by privileged threads. // DO NOT INVOKE CLIENT CODE ON THIS THREAD! ###@###.### 2001-09-21
21-09-2001

EVALUATION This is likely a problem with the underlying event generation, reassigning to awt. scott.violet@eng 2001-07-10 CTE has a fix for this bug which will go into 1.3.1 and merlin. Commit to fix in merlin (CTE fix). ###@###.### 2001-10-02
10-07-2001

WORK AROUND Use java.awt.Frame.setUndecorated(true) with a javax.swing.JFrame instead of a JWindow for the desired behavior richard.ray@eng 2001-07-10
10-07-2001