swingx
  1. swingx
  2. SWINGX-1337

NameComboBoxModel does not implement ComboBoxModel properly

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.6.1
    • Fix Version/s: 1.6.3
    • Component/s: Authentication
    • Labels:
      None
    • Environment:

      Operating System: Mac OS X
      Platform: All

    • Issuezilla Id:
      1,337

      Description

      NameComboBoxModel does not implement ComboBoxModel properly

      namely:

      public Object getElementAt(int index)

      { return userNameStore.getUserNames()[index]; }

      fails with this exception on mac os x (aqua plaf):

      Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: -1
      at
      org.jdesktop.swingx.JXLoginPane$ComboNamePanel$NameComboBoxModel.getElementAt(JXLoginPane.java:1593)
      at com.apple.laf.AquaComboBoxUI$1.itemStateChanged(AquaComboBoxUI.java:88)
      at javax.swing.JComboBox.fireItemStateChanged(JComboBox.java:1205)
      at javax.swing.JComboBox.selectedItemChanged(JComboBox.java:1262)
      at javax.swing.JComboBox.contentsChanged(JComboBox.java:1309)
      at javax.swing.AbstractListModel.fireContentsChanged(AbstractListModel.java:100)
      at
      org.jdesktop.swingx.JXLoginPane$ComboNamePanel$NameComboBoxModel.setSelectedItem(JXLoginPane.java:1587)
      at javax.swing.JComboBox.setSelectedItem(JComboBox.java:557)
      at
      org.jdesktop.swingx.autocomplete.ComboBoxAdaptor.setSelectedItem(ComboBoxAdaptor.java:104)
      at
      org.jdesktop.swingx.autocomplete.AutoCompleteDocument.setSelectedItem(AutoCompleteDocument.java:305)
      at
      org.jdesktop.swingx.autocomplete.AutoCompleteDocument.insertString(AutoCompleteDocument.java:274)
      at javax.swing.text.JTextComponent.replaceSelection(JTextComponent.java:1358)
      at
      javax.swing.text.DefaultEditorKit$DefaultKeyTypedAction.actionPerformed(DefaultEditorKit.java:864)
      at javax.swing.SwingUtilities.notifyAction(SwingUtilities.java:1639)
      at javax.swing.JComponent.processKeyBinding(JComponent.java:2851)
      at javax.swing.JComponent.processKeyBindings(JComponent.java:2886)
      at javax.swing.JComponent.processKeyEvent(JComponent.java:2814)
      at java.awt.Component.processEvent(Component.java:6125)
      at java.awt.Container.processEvent(Container.java:2085)
      at java.awt.Component.dispatchEventImpl(Component.java:4714)
      at java.awt.Container.dispatchEventImpl(Container.java:2143)
      at java.awt.Component.dispatchEvent(Component.java:4544)
      at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1850)
      at
      java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:712)
      at
      java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:990)
      at
      java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:855)
      at
      java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:676)
      at java.awt.Component.dispatchEventImpl(Component.java:4586)
      at java.awt.Container.dispatchEventImpl(Container.java:2143)
      at java.awt.Window.dispatchEventImpl(Window.java:2478)
      at java.awt.Component.dispatchEvent(Component.java:4544)
      at java.awt.EventQueue.dispatchEvent(EventQueue.java:635)
      at
      java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
      at
      java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
      at
      java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
      at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

      this is because "-1" is a valid value for index per spec:

      http://download.oracle.com/javase/1.4.2/docs/api/javax/swing/SingleSelectionModel.html#getSelectedIndex%28%29

      "Returns:
      the model's selection, or -1 if there is no selection"

      something like this resolves the issue:

      public Object getElementAt(int index) {
      if(index <0 || index > getSize())

      { return null; }

      return userNameStore.getUserNames()[index];
      }

      this "-1" happens only on mac, windows and linux run original code fine;

      thank you!

        Activity

        Hide
        andrei_pozolotin added a comment -

        thank you!

        Show
        andrei_pozolotin added a comment - thank you!
        Hide
        Karl Schaefer added a comment -

        Issue 1337: Added check for -1.

        swingx-core/src/main/java/org/jdesktop/swingx/JXLoginPane.java

        Committed revision 3868.

        Show
        Karl Schaefer added a comment - Issue 1337: Added check for -1. swingx-core/src/main/java/org/jdesktop/swingx/JXLoginPane.java Committed revision 3868.
        Hide
        Karl Schaefer added a comment -

        Taking it.

        Show
        Karl Schaefer added a comment - Taking it.

          People

          • Assignee:
            Karl Schaefer
            Reporter:
            andrei_pozolotin
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: