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

Swing BeanInfos have missing or useless default properties / events

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 5.0
    • client-libs
    • Cause Known
    • x86
    • windows_xp

      A DESCRIPTION OF THE REQUEST :
      The BeanInfos for the Swing components contain missing, misleading, and useless entries for getDefaultPropertyIndex() and getDefaultEventIndex().

      For example, JSlider has an obvious default property (value) and an equally obvious default event (ChangeEvent). But its BeanInfo reports the default property as "UI" and no default event.

      Virtually all of the Swing classes report either "UI" or "UIClassID" as their default properties. I do not believe any of them report default events.

      Judging from the JDK source code, the default property was supposed to be the first one in the list (the default Swing BeanInfo class always returns 0), but the properties are being sorted in case-insensitive order so the first entry always ends up "UI".

      JUSTIFICATION :
      When used in a form, the "value" of a component is typically just the value of its default property (or at least what *should* be its default property). This would enable automated tools to determine what properties are of most interest.

      As for the default event, in Swing, none of the default component properties are bound (they do not fire PropertyChangeEvent). They instead fire other events, such as ChangeEvent, which would be obvious choices for the default event. If these were correctly flagged, you could (relatively safely) assume that if a non-bound default property changed, the default event would be fired -- this would make it easier for automated tools to track changes to these properties.

      I currently find myself having to hard-code all of these behaviors (to listen to JSlider.value, you have to add a ChangeListener...) rather than being able to make any kind of intelligent guesses about it. I can handle the fact that the guesses won't always be right, but it would be nice to have *some* help on this.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Examples:

      JButton: label & ActionEvent
      JCheckBox: selected & ChangeEvent
      JSlider: value & ChangeEvent
      JTextField: text & no default event

      In general, every component should be reporting its main value property as its default property, and if there is an event fired when it is updated, it should be the default event.
      ACTUAL -
      The test program prints:
      ----
      javax.swing.JSlider description: A component that supports selecting a integer value from a range.
      default property is: UI
      no default event
      -----

      Make sure that the JDK's dt.jar is in the classpath so that the full BeanInfos are loaded. The test program prints the bean's description as a test of whether the BeanInfo is being loaded or not.

      ---------- BEGIN SOURCE ----------
      import java.beans.*;
      import javax.swing.*;

      public class Test {
          public static void main(String[] arg) throws Exception {
              Class bean = JSlider.class;
              BeanInfo info = Introspector.getBeanInfo(bean);
              
              System.out.println(bean.getName() + " description: " + info.getBeanDescriptor().getShortDescription()); // make sure dt.jar is available
              int defaultProperty = info.getDefaultPropertyIndex();
              if (defaultProperty == -1)
                  System.err.println("no default property");
              else
                  System.err.println("default property is: " + info.getPropertyDescriptors()[info.getDefaultPropertyIndex()].getName());

              int defaultEvent = info.getDefaultEventIndex();
              if (defaultEvent == -1)
                  System.err.println("no default event");
              else
                  System.err.println("default event is: " + info.getEventSetDescriptors()[info.getDefaultEventIndex()].getName());
          }
      }
      ---------- END SOURCE ----------

            Unassigned Unassigned
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: