Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java and Windows Look & feel

I made a swing application that scans Images; and each Image represented by a leaf I a tree

the problem that I faced is that it throws this exception

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at com.sun.java.swing.plaf.windows.XPStyle$Skin.getWidth(XPStyle.java:513)
    at com.sun.java.swing.plaf.windows.XPStyle$Skin.getWidth(XPStyle.java:517)
    at com.sun.java.swing.plaf.windows.WindowsTreeUI$ExpandedIcon.getIconWidth(WindowsTreeUI.java:138)
    at javax.swing.plaf.basic.BasicTreeUI.drawCentered(BasicTreeUI.java:1580)
    at javax.swing.plaf.basic.BasicTreeUI.paintExpandControl(BasicTreeUI.java:1464)
    at javax.swing.plaf.basic.BasicTreeUI.paint(BasicTreeUI.java:1206)
    at javax.swing.plaf.ComponentUI.update(ComponentUI.java:143)
    at javax.swing.JComponent.paintComponent(JComponent.java:763)
    at javax.swing.JComponent.paint(JComponent.java:1027)
    at javax.swing.JComponent.paintToOffscreen(JComponent.java:5122)
    at javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManager.java:285)
    at javax.swing.RepaintManager.paint(RepaintManager.java:1128)
    at javax.swing.JComponent._paintImmediately(JComponent.java:5070)
    at javax.swing.JComponent.paintImmediately(JComponent.java:4880)
    at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:723)
    at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:679)
    at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:659)
    at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:128)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
    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)

and I don't know why this appears Note: I am using Windows Look and feel

UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");

and java 1.6_22 under windows-7

like image 618
ehab refaat Avatar asked Mar 01 '11 17:03

ehab refaat


People also ask

What is Java look and feel?

With the growth in Java framework, new changes were introduced to make the UI better and thus giving developer opportunity to enhance the look of a Java Swing Application. “Look” refers to the appearance of GUI widgets and “feel” refers to the way the widgets behave.

Which is better JavaFX or Swing?

In short, Swing and JavaFX are both GUI toolkits for Java programs. Swing is the old standard toolkit that features a bigger library of GUI elements and mature IDE support. JavaFX is the newer standard with a smaller library, more consistent updates, and consistent MVC support.

What is UIManager in Java?

UIManager manages the current look and feel, the set of available look and feels, PropertyChangeListeners that are notified when the look and feel changes, look and feel defaults, and convenience methods for obtaining various default values.


1 Answers

Try this:

//Set the look and feel to users OS LaF.
    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (UnsupportedLookAndFeelException e) {
        e.printStackTrace();
    }
like image 190
Afra Avatar answered Sep 21 '22 14:09

Afra