Changing PLAF when a JComboBox is open?
I am trying to write a simple way of changing the look and feel that I can easily connect to most of the possible ways that someone might want to change the plaf (for example combo box, list, radio buttons, menus & popups etc)
The best way of doing this I have found so far is implementing ItemListener. I can just get the contents of the event when it is ItemEvent.SELECTED and change the PLAF withUIManager.setLookAndFeel(lookAndFeel);
SwingUtilities.updateComponentTreeUI(c);
where "c" was the root component to change from, given to my class.
This works fine in most cases but when using the keyboard to navigate a JComboBox, the item can be selected while the drop down list is still open. This causes the updateComponentTreeUI to error:Exception in thread"AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.plaf.basic.BasicComboBoxUI.selectNextPossibleValue(BasicComboBoxUI.java:1072)
at javax.swing.plaf.basic.BasicComboBoxUI$Actions.actionPerformed(BasicComboBoxUI.java:1432)
at javax.swing.SwingUtilities.notifyAction(SwingUtilities.java:1636)
at javax.swing.JComponent.processKeyBinding(JComponent.java:2844)
at javax.swing.JComponent.processKeyBindings(JComponent.java:2890)
at javax.swing.JComponent.processKeyEvent(JComponent.java:2807)
at javax.swing.JComboBox.processKeyEvent(JComboBox.java:1399)
at java.awt.Component.processEvent(Component.java:5815)
at java.awt.Container.processEvent(Container.java:2058)
at java.awt.Component.dispatchEventImpl(Component.java:4410)
at java.awt.Container.dispatchEventImpl(Container.java:2116)
at java.awt.Component.dispatchEvent(Component.java:4240)
at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1848)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:693)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:958)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:830)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:657)
at java.awt.Component.dispatchEventImpl(Component.java:4282)
at java.awt.Container.dispatchEventImpl(Container.java:2116)
at java.awt.Window.dispatchEventImpl(Window.java:2429)
at java.awt.Component.dispatchEvent(Component.java:4240)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
Is there a safe way of doing this or a way of avoiding the errors? Would somehow using SwingUtilities.invokeLater(Runnable) help? Is there a better way of doing what I want without using ItemListener etc?

