java - Why does Synth keeps throwing NullPointerExceptions when trying to apply a style? -
whenever try apply style jmenu or jmenuitem (via synth) lot of nullpointerexceptions whenever hover or click jmenuitems or jmenu itself, stack trace isn't giving me useful information , doesn't point anywhere @ of source files.
i loading file correctly , does display styles (apart background colors that's aside) problem lot of exceptions while working fine, program doesn't crash.
this synth lookandfeel.xml file:
<?xml version="1.0" encoding="utf-8"?> <synth> <style id="menubarstyle"> <state> <color value="gray" type="background"/> </state> </style> <bind style="menubarstyle" type="region" key="menubar"/> <style id="menustyle"> <insets top="5" bottom="3" right="10" left="10"/> <state> <color value="red" type="background"/> </state> </style> <bind style="menustyle" type="region" key="menu"/> <style id="menuitemstyle"> <insets top="5" bottom="5" left="10" right="3"/> <state> <color value="green" type="background"/> </state> </style> <bind style="menuitemstyle" type="region" key="menuitem"/> <style id="menuitemacceleratorstyle"> <state> <color value="gray" type="background"/> </state> </style> <bind style="menuitemacceleratorstyle" type="region" key="menuitem"/> </synth>
this how load file:
private void initui() { try { synthlookandfeel laf = new synthlookandfeel(); laf.load(getclass().getclassloader().getresourceasstream("lookandfeel.xml"), getclass()); uimanager.setlookandfeel(laf); } catch (parseexception e) { e.printstacktrace(); } catch (unsupportedlookandfeelexception e) { e.printstacktrace(); } }
and stack trace (printed repeatedly whenever there interaction styled components):
exception in thread "awt-eventqueue-0" java.lang.nullpointerexception @ sun.font.fontdesignmetrics$metricskey.init(fontdesignmetrics.java:217) @ sun.font.fontdesignmetrics.getmetrics(fontdesignmetrics.java:286) @ sun.swing.swingutilities2.getfontmetrics(swingutilities2.java:1113) @ javax.swing.jcomponent.getfontmetrics(jcomponent.java:1626) @ sun.swing.menuitemlayouthelper.reset(menuitemlayouthelper.java:125) @ javax.swing.plaf.synth.synthmenuitemlayouthelper.<init>(synthmenuitemlayouthelper.java:119) @ javax.swing.plaf.synth.synthgraphicsutils.paint(synthgraphicsutils.java:501) @ javax.swing.plaf.synth.synthmenuitemui.paint(synthmenuitemui.java:281) @ javax.swing.plaf.synth.synthmenuitemui.update(synthmenuitemui.java:245) @ javax.swing.jcomponent.paintcomponent(jcomponent.java:780) @ javax.swing.jcomponent.paint(jcomponent.java:1056) @ javax.swing.jcomponent.paintchildren(jcomponent.java:889) @ javax.swing.jcomponent.paint(jcomponent.java:1065) @ javax.swing.jcomponent.paintchildren(jcomponent.java:889) @ javax.swing.jcomponent.paint(jcomponent.java:1065) @ javax.swing.jcomponent.paintchildren(jcomponent.java:889) @ javax.swing.jcomponent.paint(jcomponent.java:1065) @ javax.swing.jlayeredpane.paint(jlayeredpane.java:586) @ javax.swing.jcomponent.paintchildren(jcomponent.java:889) @ javax.swing.jcomponent.paint(jcomponent.java:1065) @ javax.swing.jcomponent.painttooffscreen(jcomponent.java:5210) @ javax.swing.repaintmanager$paintmanager.paintdoublebuffered(repaintmanager.java:1579) @ javax.swing.repaintmanager$paintmanager.paint(repaintmanager.java:1502) @ javax.swing.repaintmanager.paint(repaintmanager.java:1272) @ javax.swing.jcomponent._paintimmediately(jcomponent.java:5158) @ javax.swing.jcomponent.paintimmediately(jcomponent.java:4969) @ javax.swing.repaintmanager$4.run(repaintmanager.java:831) @ javax.swing.repaintmanager$4.run(repaintmanager.java:814) @ java.security.accesscontroller.doprivileged(native method) @ java.security.protectiondomain$javasecurityaccessimpl.dointersectionprivilege(protectiondomain.java:76) @ javax.swing.repaintmanager.paintdirtyregions(repaintmanager.java:814) @ javax.swing.repaintmanager.paintdirtyregions(repaintmanager.java:789) @ javax.swing.repaintmanager.prepaintdirtyregions(repaintmanager.java:738) @ javax.swing.repaintmanager.access$1200(repaintmanager.java:64) @ javax.swing.repaintmanager$processingrunnable.run(repaintmanager.java:1732) @ java.awt.event.invocationevent.dispatch(invocationevent.java:311) @ java.awt.eventqueue.dispatcheventimpl(eventqueue.java:756) @ java.awt.eventqueue.access$500(eventqueue.java:97) @ java.awt.eventqueue$3.run(eventqueue.java:709) @ java.awt.eventqueue$3.run(eventqueue.java:703) @ java.security.accesscontroller.doprivileged(native method) @ java.security.protectiondomain$javasecurityaccessimpl.dointersectionprivilege(protectiondomain.java:76) @ java.awt.eventqueue.dispatchevent(eventqueue.java:726) @ java.awt.eventdispatchthread.pumponeeventforfilters(eventdispatchthread.java:201) @ java.awt.eventdispatchthread.pumpeventsforfilter(eventdispatchthread.java:116) @ java.awt.eventdispatchthread.pumpeventsforhierarchy(eventdispatchthread.java:105) @ java.awt.eventdispatchthread.pumpevents(eventdispatchthread.java:101) @ java.awt.eventdispatchthread.pumpevents(eventdispatchthread.java:93) @ java.awt.eventdispatchthread.run(eventdispatchthread.java:82)
i suspect problem has synth rather code suppose, tried looking on internet , in java documentation , tutorials on synth couldn't find relevant.
p.s: call method before start displaying or creating swing components.
update (and highly probable answer):
i found way solve problem, question remains in tact since still haven't got explanation why problem happening have hypothesis.
solution:
apparently font style should applied elements in order xml file not show errors, bare minimum required solve issue have discovered after experimentation:
<style id="defaultelementstyle"> <font name="verdana" size="12"/> </style> <bind style="defaultelementstyle" type="region" key=".*"/>
hypothesis
since:
- the nullpointerexception thrown whenever there change in state of jmenu/jmenuitems.
- the problem solved setting global font property
i can safely infer problem origin calling function tried read font property of changed states *(probably 1 of classes in stack trace). however, in case mentioned above default font states undefined in xml file (null) resulted in nullpointerexception, maybe class smart enough resort default font (which displayed) , prevented program failing , crashing. thoughts on subject highly appreciated since seems problem isn't common @ , requires further investigation.
Comments
Post a Comment