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

Window.toFront() unreliable on Win32

XMLWordPrintable

    • b02
    • generic, x86
    • generic, windows_nt, windows_2000



        Name: dbT83986 Date: 12/30/98


        /*

        Window.toFront() unreliable on Win32

        I am using JDK1.2 Beta4, but I was able to try this on
        JDK 1.2 FCS level M and got essentially the same results.

        The problem is that Window.toFront() doesn't work under
        most circumstances. The following sample app demonstrates
        the problem in several flavors.

        When you compile and run the app it will bring up a single
        simple window titled "Window 1". Every 5 seconds it will
        cause toFront() to be called on the Window. If you click
        on some other app (so that the Java program drops behind
        the other windows on the desktop) you will note that
        Window 1 *does* come to the top as expected.

        But now click on the titlebar of Window 1, which activates
        it and brings it to the top. Then click on a non-Java app
        again, and you will notice that toFront no longer works.
        Once you have explicitly activated the Window it seems as
        though toFront becomes a no-op from then on.

        There is a second flavor of the same problem, almost
        certainly related. First uncomment the block of code
        indicated in the constructor method and recompile. Now
        the app will start up creating *two* windows instead of
        one. In this scenario toFront() *never* works at all.

        These problems may be related to Win32's notion of
        "foreground thread"; I suspect that if there was an API
        to activate a Window and make the AWT event queue thread
        the "foreground thread" then whatever toFront() is doing
        might start to work.

        We are trying to build a complex Java IDE that interacts
        with some non-Java components; we often need to force one
        of the Java Windows to the top so it will not be obscured
        by the non-Java windows. As long as toFront() is broken
        it makes the IDE very frustrating to use, since the Java
        Window you want to work on is never on top when you need it.

        */

        import java.awt.*;
        import java.awt.event.*;
        import com.sun.java.swing.*;

        public class ToFrontTest implements Runnable, ActionListener
        {
        public static void main(String args[])
        {
        new ToFrontTest();
        }

        public JFrame jf1;
        public JFrame jf2;
        public JButton jb1;
        public JButton jb2;

        public ToFrontTest()
        {
        jf1 = new JFrame("Window 1");
        jb1 = new JButton("Quit");

        jf1.setSize(300,100);
        jf1.getContentPane().setLayout(new FlowLayout());
        jf1.getContentPane().add(jb1);

        jf1.show();

        jb1.addActionListener(this);

        /***************** Uncomment this block to add a second window
        jf2 = new JFrame("Window 2");
        jb2 = new JButton("Do Nothing");

        jf2.setLocation(300,0);
        jf2.setSize(300,100);
        jf2.getContentPane().setLayout(new FlowLayout());
        jf2.getContentPane().add(jb2);

        jf2.show();
        /******************/

        while (true)
        {
        for (int i=5; i>0; i--)
        {
        System.out.println(i + "...");

        try
        {
        Thread.currentThread().sleep(1000);
        }
        catch (Exception ex)
        {
        }
        }

        //
        // Just in case, cause "toFront" to be run
        // on the AWT Event Thread. (It actually
        // seems to make no difference where the
        // "toFront" is done, it behaves the same.)
        //
        SwingUtilities.invokeLater(this);
        }
        }

        public void actionPerformed(ActionEvent e)
        {
        System.exit(0);
        }

        public void run()
        {
        System.out.println("Bring 'Window 1' toFront");
        jf1.toFront();
        }
        }
        (Review ID: 40483)
        ======================================================================

        Name: vi73552 Date: 06/14/99


        The method toFront() does not work since JDK1.2beta?
        It does not work in 1.2, 1.2.1, 1.2.2.
        I am currently not able to deploy my messaging application since it's not possible to open windows or frames that show above ALL other windows.
        (Review ID: 84311)
        ======================================================================

        <<< Addtional information >>>

         I tried the above sample code with a little modification and found
         out that it still happned.

         1. reproducing
          1) Modify the above source code and compile by JDK1.3.0fcs

        *** ToFrontTest.java Mon Oct 1 11:15:22 2001
        --- ToFrontTest.java-rev Mon Oct 1 11:16:33 2001
        ***************
        *** 1,6 ****
          import java.awt.*;
          import java.awt.event.*;
        ! import com.sun.java.swing.*;
          
          public class ToFrontTest implements Runnable, ActionListener
          {
        --- 1,6 ----
          import java.awt.*;
          import java.awt.event.*;
        ! import javax.swing.*;
          
          public class ToFrontTest implements Runnable, ActionListener
          {

         2) Invoke "java ToFronTest"
           -> Here, you will see the behavior as the above-mentioned.


         2. Configration
           
            MPU: Pentium II 400[MHz]
            Memory: 256[MB]
            OS: windows98(Second Edition, Japanes)

            MPU: Celeron 300[MHz]
            Memory: 128[MB]
            OS: windows2000(SP2, Japanese)

            JDK: JDK1.3.0fcs, JDK1.3.1_01 and Merlin-beta3-b80

         3. Note
         
            This does not happen on Windows NT(sp5, Japanese).
        =========================================================================



          

            

              duke J. Duke
              dblairsunw Dave Blair (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: