我正在尝试使用创建一个定制的外观和感觉。
我成功地使用了一个教程( Oracle/Sun的外观教程 )来进行实验,并设法实现了按钮、面板等。
我现在的问题是,我想装饰窗户/框架。
我读了一些关于它的内容,并在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);按钮和面板会被剥皮,但当然,窗口/JFrame没有。
我只是找不到关于如何用Synth-XML来皮肤/装饰窗口/JFrame的源代码。有人能帮我吗?
发布于 2013-05-14 07:42:07
JFrame/JDialog/JWindowJFrame/JDialog/JWindow基于来自本机操作系统的对等点,默认情况下具有与从本机操作系统调用的其他窗口相同的装饰类型(颜色、字体、字体大小)。发布于 2013-05-14 10:43:56
可以用你自己的L&F装饰JFrame,JDialog,甚至JWindow,但我不确定Synth能做到这一点。至少我没有找到任何关于这方面的信息。
L&F类实体,Synthetica和其他人使用一个小的欺骗来装饰JFrame和JDialog -当setDefaultLookAndFeelDecorated被设置为true JRootPane UI时,禁用本机框架/对话框装饰,而只是显示它自己的样式。此外,一些本地特性,如非不透明框架/对话框,在这种情况下非常方便,使您感到窗口实际上是用不同的风格装饰(如果没有这些功能,您就无法创建一个很好的窗口阴影效果)。
https://stackoverflow.com/questions/16537179
复制相似问题