Zmiana LAF w trakcie działania programu

0

Chciałbym zmienić Look And Feel w trakcie wyświetlania ramki. Niestety,

UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");

nie zmienia wyglądu, zaś dodanie linijki repaint() lub revalidate() wywołuje NullPointerException, w którym nie bierze udziału żadna moja klasa:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
	at sun.font.FontDesignMetrics$MetricsKey.init(FontDesignMetrics.java:217)
	at sun.font.FontDesignMetrics.getMetrics(FontDesignMetrics.java:286)
	at sun.swing.SwingUtilities2.getFontMetrics(SwingUtilities2.java:1012)
	at javax.swing.JComponent.getFontMetrics(JComponent.java:1624)
	at sun.swing.MenuItemLayoutHelper.reset(MenuItemLayoutHelper.java:125)
	at javax.swing.plaf.synth.SynthMenuItemLayoutHelper.<init>(SynthMenuItemLayoutHelper.java:119)
	at javax.swing.plaf.synth.SynthGraphicsUtils.paint(SynthGraphicsUtils.java:498)
	at javax.swing.plaf.synth.SynthMenuUI.paint(SynthMenuUI.java:283)
	at javax.swing.plaf.synth.SynthMenuUI.update(SynthMenuUI.java:248)
	at javax.swing.JComponent.paintComponent(JComponent.java:778)
	at javax.swing.JComponent.paint(JComponent.java:1054)
	at javax.swing.JComponent.paintChildren(JComponent.java:887)
	at javax.swing.JComponent.paint(JComponent.java:1063)
	at javax.swing.JComponent.paintChildren(JComponent.java:887)
	at javax.swing.JComponent.paint(JComponent.java:1063)
	at javax.swing.JLayeredPane.paint(JLayeredPane.java:585)
	at javax.swing.JComponent.paintChildren(JComponent.java:887)
	at javax.swing.JComponent.paint(JComponent.java:1063)
	at javax.swing.JComponent.paintToOffscreen(JComponent.java:5221)
	at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1512)
	at javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1443)
	at javax.swing.RepaintManager.paint(RepaintManager.java:1236)
	at javax.swing.JComponent._paintImmediately(JComponent.java:5169)
	at javax.swing.JComponent.paintImmediately(JComponent.java:4980)
	at javax.swing.RepaintManager$3.run(RepaintManager.java:796)
	at javax.swing.RepaintManager$3.run(RepaintManager.java:784)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
	at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:784)
	at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:757)
	at javax.swing.RepaintManager.prePaintDirtyRegions(RepaintManager.java:706)
	at javax.swing.RepaintManager.access$1000(RepaintManager.java:62)
	at javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1651)
	at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:727)
	at java.awt.EventQueue.access$200(EventQueue.java:103)
	at java.awt.EventQueue$3.run(EventQueue.java:688)
	at java.awt.EventQueue$3.run(EventQueue.java:686)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:697)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)

Zna ktoś sposób na wyminięcie tego czegoś i zmianę LAF programu?

1

http://docs.oracle.com/javase/7/docs/api/javax/swing/UIManager.html

Once the look and feel has been changed it is imperative to invoke updateUI on all JComponents. The method SwingUtilities.updateComponentTreeUI(java.awt.Component) makes it easy to apply updateUI to a containment hierarchy. Refer to it for details. The exact behavior of not invoking updateUI after changing the look and feel is unspecified. It is very possible to receive unexpected exceptions, painting problems, or worse.

Innym powodem mogą być problemy z synchronizacją - wołasz to podczas repaint, etc.

1 użytkowników online, w tym zalogowanych: 0, gości: 1