因此,我正在尝试使用 java 合成器创建自定义 LookAndFeel,但在绑定自定义按钮时遇到问题。(退出按钮有不同的外观)。
这是我的合成器文件中的按钮:
<!-- Button -->
<style id="buttonStyle">
<property key="Button.textShiftOffset" type="integer" value="1"/>
<insets top="2" left="2" right="2" bottom="2"/>
<state>
<color value="#000000" type="BACKGROUND"/>
<imagePainter method="buttonBackground" path="/rstk/resources/pictures/parts/button.jpg" sourceInsets="2 2 2 2"/>
</state>
<state value="PRESSED">
<color value="#9BC3B1" type="BACKGROUND"/>
<imagePainter method="buttonBackground" path="/rstk/resources/pictures/parts/button_p.jpg" sourceInsets="2 2 2 2"/>
</state>
<state value="MOUSE_OVER">
<color value="#9BC3B1" type="BACKGROUND"/>
<imagePainter method="buttonBackground" path="/rstk/resources/pictures/parts/button_h.jpg" sourceInsets="2 2 2 2"/>
</state>
</style>
<bind style="buttonStyle" type="region" key="Button"/>
<!-- Exit Button -->
<style id="exitStyle">
<property key="Button.textShiftOffset" type="integer" value="1"/>
<insets top="1" left="1" right="1" bottom="1"/>
<state>
<imagePainter method="buttonBackground" path="/rstk/resources/pictures/parts/exit.jpg" sourceInsets="2 2 2 2"/>
</state>
<state value="PRESSED">
<color value="#9BC3B1" type="BACKGROUND"/>
<imagePainter method="buttonBackground" path="/rstk/resources/pictures/parts/exit_p.jpg" sourceInsets="2 2 2 2"/>
</state>
<state value="MOUSE_OVER">
<color value="#9BC3B1" type="BACKGROUND"/>
<imagePainter method="buttonBackground" path="/rstk/resources/pictures/parts/exit_h.jpg" sourceInsets="2 2 2 2"/>
</state>
</style>
<bind style="exitStyle" type="region" key="Exit"/>
这是创建按钮的代码。
JButton exit = new JButton("Exit");
exit.setName("exit");
我试过去掉普通的按钮样式,这样我就只有自定义按钮了,但这不起作用。我还尝试让 buttonStyle 中没有任何内容,但这没有用,它只是拾取了整体风格:
<style id="backingStyle">
<opaque value="TRUE"/>
<font name="Dialog" size="11"/>
<state>
<color value="#2B271C" type="BACKGROUND"/>
<color value="YELLOW" type="FOREGROUND"/>
</state>
</style>
<bind style="backingStyle" type="region" key=".*"/>