PDA

Click to See Complete Forum and Search --> : [RESOLVED] "Invalid index" on JFileChooser


ComputerJy
Mar 31st, 2008, 07:24 AM
I have no idea why this problem is happening, but whenever I try the following code:jFileOpenProject.setCurrentDirectory(myFile);where jFileOpenProject is a JFileChooser and myFile is a File object pointing to a directory.
I get the following:

java.lang.IndexOutOfBoundsException: Invalid index
at javax.swing.DefaultRowSorter.convertRowIndexToModel(DefaultRowSorter.java:497)
at sun.swing.FilePane$SortableListModel.getElementAt(FilePane.java:525)
at javax.swing.plaf.basic.BasicListUI.updateLayoutState(BasicListUI.java:1336)
at javax.swing.plaf.basic.BasicListUI.maybeUpdateLayoutState(BasicListUI.java:1287)
at javax.swing.plaf.basic.BasicListUI.getCellBounds(BasicListUI.java:928)
at javax.swing.JList.getCellBounds(JList.java:1600)
at javax.swing.JList.ensureIndexIsVisible(JList.java:1116)
at sun.swing.FilePane.ensureIndexIsVisible(FilePane.java:1514)
at sun.swing.FilePane.doDirectoryChanged(FilePane.java:1440)
at sun.swing.FilePane.propertyChange(FilePane.java:1487)
at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:339)
at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:276)
at java.awt.Component.firePropertyChange(Component.java:7865)
at javax.swing.JFileChooser.setCurrentDirectory(JFileChooser.java:568)
at JFrameMain.initDialogs(JFrameMain.java:1215)
Any ideas??

ComputerJy
Mar 31st, 2008, 04:05 PM
After 3 hours of researching I found out that some smart guy had the same problem and tried to blame it on the JDK (http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6637181) - which is a stupid idea, since this method has been settings there since the swing was created - so he got spanked by the bug db admin saying that the whole test case he provided was wrong and that he's been working with Swing from the wrong thread. Instead.. well, read this (http://java.sun.com/docs/books/tutorial/uiswing/concurrency/initial.html) if you're interested