我遇到了同样的问题,但至少在我的情况下,这与Windows或Java版本无关。
创建JFileChooser时,Windows外观已经尝试通过请求所有可见项(包括网络共享的图标)的图标来计算当前目录组合框的大小。在我的情况下,我的一些网络共享不可用。
这是我在Java 8和Windows 10上的堆栈跟踪:
Thread [AWT-EventQueue-0]
Unsafe.park(boolean, long) line: not available [native method]
LockSupport.park(Object) line: 175
FutureTask<V>.awaitDone(boolean, long) line: 429
FutureTask<V>.get() line: 191
Win32ShellFolderManager2$ComInvoker.invoke(Callable<T>) line: 582
ShellFolder.invoke(Callable<T>, Class<E>) line: 518
ShellFolder.invoke(Callable<T>) line: 504
Win32ShellFolder2.getIcon(boolean) line: 968
WindowsFileSystemView(FileSystemView).getSystemIcon(File) line: 243
WindowsFileChooserUI$WindowsFileView.getIcon(File) line: 1300
JFileChooser.getIcon(File) line: 1609
WindowsFileChooserUI$DirectoryComboBoxRenderer.getListCellRendererComponent(JList, Object, int, boolean, boolean) line: 998
BasicListUI.updateLayoutState() line: 1361
BasicListUI.maybeUpdateLayoutState() line: 1311
BasicListUI$Handler.valueChanged(ListSelectionEvent) line: 2623
DefaultListSelectionModel.fireValueChanged(int, int, boolean) line: 184
DefaultListSelectionModel.fireValueChanged(int, int) line: 164
DefaultListSelectionModel.fireValueChanged() line: 211
DefaultListSelectionModel.changeSelection(int, int, int, int, boolean) line: 405
DefaultListSelectionModel.changeSelection(int, int, int, int) line: 415
DefaultListSelectionModel.setSelectionInterval(int, int) line: 459
BasicComboPopup$1(JList<E>).setSelectedIndex(int) line: 2216
BasicComboPopup.setListSelection(int) line: 1186
BasicComboPopup.access$300(BasicComboPopup, int) line: 65
BasicComboPopup$Handler.itemStateChanged(ItemEvent) line: 1015
WindowsFileChooserUI$2(JComboBox<E>).fireItemStateChanged(ItemEvent) line: 1223
WindowsFileChooserUI$2(JComboBox<E>).selectedItemChanged() line: 1280
WindowsFileChooserUI$2(JComboBox<E>).contentsChanged(ListDataEvent) line: 1330
WindowsFileChooserUI$DirectoryComboBoxModel(AbstractListModel<E>).fireContentsChanged(Object, int, int) line: 118
WindowsFileChooserUI$DirectoryComboBoxModel.setSelectedItem(Object) line: 1140
WindowsFileChooserUI$DirectoryComboBoxModel.addItem(File) line: 1111
WindowsFileChooserUI$DirectoryComboBoxModel.access$800(WindowsFileChooserUI$DirectoryComboBoxModel, File) line: 1041
WindowsFileChooserUI.doDirectoryChanged(PropertyChangeEvent) line: 730
WindowsFileChooserUI.access$1100(WindowsFileChooserUI, PropertyChangeEvent) line: 55
WindowsFileChooserUI$11.propertyChange(PropertyChangeEvent) line: 821
PropertyChangeSupport.fire(PropertyChangeListener[], PropertyChangeEvent) line: 335
PropertyChangeSupport.firePropertyChange(PropertyChangeEvent) line: 327
PropertyChangeSupport.firePropertyChange(String, Object, Object) line: 263
JFileChooser(Component).firePropertyChange(String, Object, Object) line: 8434
JFileChooser.setCurrentDirectory(File) line: 598
JFileChooser.<init>(File, FileSystemView) line: 344
JFileChooser.<init>(File) line: 326
FileChooser.<clinit>() line: 15
...
我看到两个解决方案:
1.像Joop Eggen提到的那样,在你需要它之前很长时间就初始化您的文件选择器,或者安装自己的UI,尝试在额外线程中检索图标,并仅返回那些立即可用的图标。
2. 安装自己的UI,尝试在额外的线程中检索图标,并只返回那些可以立即使用的图标。
C:\Windows\System32
。图标加载速度较慢。 - Johannes Kuhn