2012-11-26 6 views
1

신스 스타일을 실험하고 있는데, 다음과 같은 문제가 생겨서 어떤 대답을 찾지 못했습니다. 나는 SynthLookAndFeel에 객체자바에서 신스 스타일을로드하는 법

private void initializeStyle() { 
    SynthLookAndFeel laf = new SynthLookAndFeel(); 
    try { 
     laf.load(this.getClass().getResourceAsStream("Style.xml"), this.getClass()); 
     UIManager.setLookAndFeel(laf); 
    } catch (ParseException | UnsupportedLookAndFeelException e) { 
     e.printStackTrace(); 
    } 
} 

나는 다음과 같은 예외를 얻을이 코드를 실행하려고로하는 XML 파일을로드하기 위해 다음과 같은 XML 파일

<?xml version="1.0" encoding="UTF-8"?> 
<synth> 
    <style id="button"> 
     <state> 
      <color value="blue" type="BACKGROUND"/> 
      <color value="yellow" type="FOREGROUND"/> 
     </state> 
    </style> 
    <bind style="button" type="region" key="Button"/> 
</synth> 

다음과 같은 자바 코드를

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: You must supply an InputStream, StyleFactory and Class or URL 

이 문제를 해결하는 방법에 대한 제안은 환영 할만한 것이 아닙니다.

답변

2

Advanced Synth에서 좋은 예를 찾을 수 있습니다.

당신이 그 예에서 볼 수

<imageIcon id="check_off" path="images/checkbox_off.png"/> 

checkbox_off.png 거주지 :

SynthLookAndFeel synth = new SynthLookAndFeel(); 
synth.load(SynthFrame.class.getResourceAsStream("demo.xml"), SynthFrame.class); 
UIManager.setLookAndFeel(synth); 

그리고 demo.synth 패키지, SynthFrame 클래스의 같은에서 demo.xml 생활이 XML 일부 이미지가 포함 된 경우 demo.synth.images 패키지.

이 정보가 도움이되기를 바랍니다.

+0

이 도움이,하지만 내 사용자 인터페이스는 어울리는 스타일을 보여주는되지 않습니다. – Exevan

+1

프레임을 시작하기 전에 스타일을로드하십시오. 스타일을로드하려면'EventQueue.invokeAndWait()'메소드를 사용하고 프레임을 시작하려면'EventQueue.invokeLater()'메소드를 사용할 수 있습니다. –

0

메인 CALSS :

SynthLookAndFeel에 새로운 SynthLookAndFeel에의 LookAndFeel =(); lookAndFeel.load (TestRApp.class.getResourceAsStream (synthFile), TestRApp.class); UIManager.setLookAndFeel (lookAndFeel);

synth.xml 파일

<style id="panelStyle"> 
    <imagePainter method="panelBackground" path="images/main-bg.png" sourceInsets="0 0 0 0" stretch="true"/> 
</style> 
<bind style="panelStyle" type="region" key="Panel"/>