如果我有一个已经存在的按钮样式,我该如何实现自定义java合成按钮样式?
所以我试图使用java合成器创建自定义LookAndFeel,并且我在绑定自定义按钮时遇到问题。 (退出按钮具有不同的外观)。
以下是我的synth文件中的按钮:
<!-- 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=".*"/>
没有找到相关结果
已邀请:
2 个回复
犁攀富
请注意,唯一的区别是type =“name and key =”ExitButton“(或者您选择为您的类命名扩展JButton的任何内容)。此外,键的值必须与您创建并希望用于的类的名称相匹配这种风格的按钮。 希望这可以帮助。
响摔衅幸
应该
那应该是它!告诉我你是否遇到了更多问题。