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

FileChooser class doesn't work with Motif lookandfeel.

XMLWordPrintable

      Cannot use FileChooser with Motif.

      The problem seems to be in "MotifFileChooserUI" line 224

      which calls "setModel". "MetalFileChooserUI" does not call "setModel" at this
      point.

      The call in "MotifFileChooserUI" ends up calling
      "com.sun.java.swing.JComboBox.setSelectedIndex(0)" the index at zero
      fails the comparision as = to size on line 396.

         public void setSelectedIndex(int anIndex) {
              int size = dataModel.getSize();
       
           if ( anIndex == -1 ) {
               setSelectedItem( null );
           }
              else if ( anIndex < -1 || anIndex >= size ) {
                  throw new IllegalArgumentException("setSelectedIndex: " + anIndex + " out of bounds");

      The example code: View.java and VFrame.java are attached.

      compile and run, select File -> Open to see the error.

      change which line is commented out in View.java to choose between motif and
      metal.











         public void setSelectedIndex(int anIndex) {
              int size = dataModel.getSize();
       
           if ( anIndex == -1 ) {
               setSelectedItem( null );
           }
              else if ( anIndex < -1 || anIndex >= size ) {
                  throw new IllegalArgumentException("setSelectedIndex: " + anIndex + " out of bounds");


      javac View.java VFrame.java
      illium% java View
      Exception occurred during event dispatching:
      java.lang.IllegalArgumentException: setSelectedIndex: 0 out of bounds
      at com.sun.java.swing.JComboBox.setSelectedIndex(JComboBox.java:397)
      at com.sun.java.swing.plaf.basic.BasicComboPopup$PropertyChangeHandler.propertyChange(BasicComboPopup.java:556)
      at com.sun.java.swing.event.SwingPropertyChangeSupport.firePropertyChange(SwingPropertyChangeSupport.java:151)
      at com.sun.java.swing.JComponent.firePropertyChange(JComponent.java:2751)
      at com.sun.java.swing.JComboBox.setModel(JComboBox.java:186)
      at com.sun.java.swing.plaf.motif.MotifFileChooserUI.installComponents(MotifFileChooserUI.java:224)
      at com.sun.java.swing.plaf.basic.BasicFileChooserUI.installUI(BasicFileChooserUI.java:100)
      at com.sun.java.swing.plaf.motif.MotifFileChooserUI.installUI(MotifFileChooserUI.java:161)
      at com.sun.java.swing.JComponent.setUI(JComponent.java:249)
      at com.sun.java.swing.JFileChooser.updateUI(JFileChooser.java:1158)
      at com.sun.java.swing.JFileChooser.setup(JFileChooser.java:249)
      at com.sun.java.swing.JFileChooser.<init>(JFileChooser.java:225)
      at com.sun.java.swing.JFileChooser.<init>(JFileChooser.java:188)
      at VFrame.loadFile(VFrame.java:120)
      at VFrame.actionPerformed(VFrame.java:100)
      at com.sun.java.swing.AbstractButton.fireActionPerformed(AbstractButton.java:939)
      at com.sun.java.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:974)
      at com.sun.java.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:378)
      at com.sun.java.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:250)
      at com.sun.java.swing.AbstractButton.doClick(AbstractButton.java:201)
      at com.sun.java.swing.plaf.motif.MotifMenuItemUI$MouseInputHandler.mouseReleased(MotifMenuItemUI.java:94)
      at java.awt.Component.processMouseEvent(Component.java:2345)
      at java.awt.Component.processEvent(Component.java:2190)
      at java.awt.Container.processEvent(Container.java:910)
      at java.awt.Component.dispatchEventImpl(Component.java:1799)
      at java.awt.Container.dispatchEventImpl(Container.java:955)
      at java.awt.Component.dispatchEvent(Component.java:1731)
      at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:1733)
      at java.awt.LightweightDispatcher.processMouseEvent(Container.java:1531)
      at java.awt.LightweightDispatcher.dispatchEvent(Container.java:1447)
      at java.awt.Container.dispatchEventImpl(Container.java:942)
      at java.awt.Window.dispatchEventImpl(Window.java:491)
      at java.awt.Component.dispatchEvent(Component.java:1731)
      at java.awt.EventDispatchThread.run(EventDispatchThread.java:79)
      illium%

            jeff Jeff Dinkins
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: