Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4478302

Moving a JWindow does not generate corresponding event AND prob w/ setLocation

XMLWordPrintable

    • 02
    • sparc
    • solaris_2.6


        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

              duke J. Duke
              duke J. Duke
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: