views:

214

answers:

3

Hello,

on Windows systems. I get the follwing NPE with the FileChooser. It is a known bug that is not fixed by sun yet. http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6342301

Does somebody know a workaround to prevent this exception?

Thanks. André

Exception in thread "AWT-EventQueue-2" java.lang.NullPointerException at javax.swing.plaf.metal.MetalFileChooserUI$IndentIcon.getIconWidth(Unknown Source) at javax.swing.SwingUtilities.layoutCompoundLabelImpl(Unknown Source) at javax.swing.SwingUtilities.layoutCompoundLabel(Unknown Source) at javax.swing.plaf.basic.BasicLabelUI.layoutCL(Unknown Source) at javax.swing.plaf.basic.BasicLabelUI.getPreferredSize(Unknown Source) at javax.swing.JComponent.getPreferredSize(Unknown Source) at javax.swing.plaf.basic.BasicListUI.updateLayoutState(Unknown Source) at javax.swing.plaf.basic.BasicListUI.maybeUpdateLayoutState(Unknown Source) at javax.swing.plaf.basic.BasicListUI$Handler.valueChanged(Unknown Source) at javax.swing.DefaultListSelectionModel.fireValueChanged(Unknown Source) at javax.swing.DefaultListSelectionModel.fireValueChanged(Unknown Source) at javax.swing.DefaultListSelectionModel.fireValueChanged(Unknown Source) at javax.swing.DefaultListSelectionModel.changeSelection(Unknown Source) at javax.swing.DefaultListSelectionModel.changeSelection(Unknown Source) at javax.swing.DefaultListSelectionModel.setSelectionInterval(Unknown Source) at javax.swing.JList.setSelectedIndex(Unknown Source) at javax.swing.plaf.basic.BasicComboPopup.setListSelection(Unknown Source) at javax.swing.plaf.basic.BasicComboPopup.access$300(Unknown Source) at javax.swing.plaf.basic.BasicComboPopup$Handler.itemStateChanged(Unknown Source) at javax.swing.JComboBox.fireItemStateChanged(Unknown Source) at javax.swing.JComboBox.selectedItemChanged(Unknown Source) at javax.swing.JComboBox.contentsChanged(Unknown Source)

+1  A: 

In the bug report that you linked to, they also mention a workaround. It seems to come down to calling the methods in a specific order. Have you tried that?

A DESCRIPTION OF THE PROBLEM : There appears to be an undocumented bad intereaction between explicitely setting the UI and removing all file filters, even temporarily. If the latter is done before setting the ui, trying to display a file dialog will throw an exception but not if the ui was set prior to messing with the filters. Maybe it is possible to make the code more robust against this or to include a warning in the docs?

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM : Run the attached program: it will not bomb. Then move the setUI line to the bottom of the constructor and try again: it will.

Thilo
+1  A: 

So, now with registered account :)

The problem with these steps in the mentioned link is, that the look and feel and therefor the UI is set globaly in our software. So the UI is set before I'm able to manipulate the file filters.

Edit: Missunderstood the code for reproduction. The exampled works as mentioned. Thanks.

André
A: 

It looks like the workaround description says you should try to set the UI before manipulating the filters. Does this not work?

If that doesn't work, is it possible to create an instance of your manipulated FileFilters at the same point that you are setting your UI?

Epaga