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

JFrame.EXIT_ON_CLOSE can be removed in favour of WindowConstants.EXIT_ON_CLOSE

XMLWordPrintable

    • b56
    • generic
    • generic

          - In JDK 1.2 javax.swing.WindowConstants interface was added.
          - But unfortunately WindowConstants didn't contain EXIT_ON_CLOSE constant, later in jdk 1.3 this constant was added to the JFrame class, which implements WindowConstants.
          - Later it was realized that it should be added to the WindowConstants instead, and this was fixed in jdk 1.4

        EXIT_ON_CLOSE fields are static constant variables (JLS 4.12.4). When source code references either field, a Java compiler is required to inline the field's value into the resulting class file (JLS 14.21).

        This means that removing EXIT_ON_CLOSE from JFrame is binary compatible,
        because no class file actually refers to the field in JFrame directly (JLS 13.4.9).

        In addition, removing EXIT_ON_CLOSE from JFrame is source compatible,
        because JFrame continues to have an EXIT_ON_CLOSE member (via
        inheritance from WindowConstants) so code which refers to
        JFrame.EXIT_ON_CLOSE will recompile.

         javax.swing.WindowConstants:
              /**
               * The exit application default window close operation. Attempting
               * to set this on Windows that support this, such as
               * <code>JFrame</code>, may throw a <code>SecurityException</code> based
               * on the <code>SecurityManager</code>.
               * It is recommended you only use this in an application.
               *
               * @since 1.4
               * @see JFrame#setDefaultCloseOperation
               */
              public static final int EXIT_ON_CLOSE = 3;

         javax.swing.JFrame implements WindowConstants,:
              /**
               * The exit application default window close operation. If a window
               * has this set as the close operation and is closed in an applet,
               * a <code>SecurityException</code> may be thrown.
               * It is recommended you only use this in an application.
               *
               * @since 1.3
               */
              public static final int EXIT_ON_CLOSE = 3;

          There are no Sub-Tasks for this issue.

              serb Sergey Bylokhov
              serb Sergey Bylokhov
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: