Class ActionSupportForJDK5


  • public class ActionSupportForJDK5
    extends java.lang.Object
    In JDK6, Swing adds three new properties on Action class: SELECTED_KEY, DISPLAYED_MNEMONIC_INDEX_KEY and LARGE_ICON. You can find more information at http://weblogs.java.net/blog/zixle/archive/2005/11/changes_to_acti.html

    However, for users who are still using JDK5, you are out of luck. In this class, we provide a simple way to use those new properties on JDK5.

    First of all, you need to call this method.

     Action action = new AbstractAction("Text") {...};
     JButton button = new JButton(action);
     ActionSupportForJDK5.install(button);
     

    When you about to change the selected state of action, you call ActionSupportForJDK5.setActionSelected(action, selected). The selected value could be true or false. This call will automatically make the button selected or not selected.

    There are also setDisplayedMnemonicIndex and setLargeIcon methods on ActionSupportForJDK5 to the other two new properties.

    Last but not least, if you don't use the button anymore, it is a good practice to call ActionSupportForJDK5.uninstall to remove the installed listeners.

    • Field Detail

      • DISPLAYED_MNEMONIC_INDEX_KEY

        public static final java.lang.String DISPLAYED_MNEMONIC_INDEX_KEY
        See Also:
        Constant Field Values
      • CLIENT_PROPERTY_PROPERTY_CHANGE_LISTENER

        protected static final java.lang.String CLIENT_PROPERTY_PROPERTY_CHANGE_LISTENER
        See Also:
        Constant Field Values
      • CLIENT_PROPERTY_ITEM_LISTENER

        protected static final java.lang.String CLIENT_PROPERTY_ITEM_LISTENER
        See Also:
        Constant Field Values
    • Constructor Detail

      • ActionSupportForJDK5

        public ActionSupportForJDK5()
    • Method Detail

      • setActionSelected

        public static void setActionSelected​(javax.swing.Action action,
                                             boolean selected)
      • isActionSelected

        public static boolean isActionSelected​(javax.swing.Action action)
      • setDisplayedMnemonicIndex

        public static void setDisplayedMnemonicIndex​(javax.swing.Action action,
                                                     int newIndex)
      • hasDisplayedMnemonicIndex

        public static boolean hasDisplayedMnemonicIndex​(javax.swing.Action action)
      • getDisplayedMnemonicIndex

        public static int getDisplayedMnemonicIndex​(javax.swing.Action action)
      • setLargeIcon

        public static void setLargeIcon​(javax.swing.Action action,
                                        javax.swing.Icon icon)
      • getLargeIcon

        public static javax.swing.Icon getLargeIcon​(javax.swing.Action action)
      • install

        public static void install​(javax.swing.AbstractButton button,
                                   javax.swing.Action action)
      • install

        public static void install​(javax.swing.AbstractButton button)
      • uninstall

        public static void uninstall​(javax.swing.AbstractButton button,
                                     javax.swing.Action action)
      • uninstall

        public static void uninstall​(javax.swing.AbstractButton button)
      • actionPropertyChanged

        public static void actionPropertyChanged​(javax.swing.AbstractButton button,
                                                 javax.swing.Action action,
                                                 java.lang.String propertyName)