我試圖用Synth-Framework創建一個自定義的外觀。Java-LAF:如何使用Synth-XML創建裝飾?
我成功地使用教程(Look-And-Feel Tutorial by Oracle/Sun )進行試驗,並設法皮膚按鈕,面板等
的問題,我現在就是,我想裝飾的窗口/ JFrame中。
我讀了一些東西有關,並與MetalLookAndFeel和今典的作品嚐試過了:
try{
UIManager.setLookAndFeel(new MetalLookAndFeel());
}catch(UnsupportedLookAndFeelException e){
}
javax.swing.JFrame.setDefaultLookAndFeelDecorated(true);
new SFframe().setVisible(true);
現在我試圖用我自己的LAF:
<?xml version="1.0" encoding="UTF-8"?>
<synth>
<!-- Style that all regions will use -->
<style id="backingStyle">
<opaque value="TRUE"/>
<font name="Dialog" size="14"/>
<state>
<color value="#04688D" type="BACKGROUND"/>
<color value="#FFFFFF" type="FOREGROUND"/>
</state>
<defaultsProperty key="Synthetica.window.decoration" type="boolean" value="true"/>
</style>
<bind style="backingStyle" type="region" key=".*"/>
<style id="button">
<!-- Shift the text one pixel when pressed -->
<property key="Button.textShiftOffset" type="integer" value="1"/>
<!-- set size of buttons -->
<insets top="4" left="4" bottom="4" right="4"/>
<state>
<imagePainter method="buttonBackground" path="/synth/images/Button.png" sourceInsets="4 4 4 4"/>
<font name="Dialog" size="16"/>
<color type="TEXT_FOREGROUND" value="#FFFFFF"/>
</state>
<state value="PRESSED">
<imagePainter method="buttonBackground" path="/synth/images/Button_pressed.png" sourceInsets="4 4 4 4"/>
</state>
<state value="MOUSE_OVER">
<imagePainter method="buttonBackground" path="/synth/images/Button_over.png" sourceInsets="4 4 4 4"/>
</state>
</style>
<bind style="button" type="region" key="Button"/>
</synth>
我的代碼使用加載LAF看起來是這樣的:
SynthLookAndFeel laf = new SynthLookAndFeel();
try{
InputStream in = SFframe.class.getResourceAsStream("/synth/synth.xml");
laf.load(in, SFframe.class);
UIManager.setLookAndFeel(laf);
}catch(ParseException | UnsupportedLookAndFeelException e){
e.printStackTrace();
}
javax.swing.JFrame.setDefaultLookAndFeelDecorated(true);
new SFframe().setVisible(true);
按鈕和麪板更換皮膚,當然,窗口/ JFR艾美沒有。
我只是找不到一個關於如何使用Synth-XML皮膚/裝飾Window/JFrame的源代碼。 有人可以幫我嗎?
+1用於打擾合成器:-) – mKorbel 2013-05-14 07:35:49