Java自定义按钮2014-10-20 16:22:48
( 还没有投票,继续加油! )
import java.awt.FlowLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.UIManager; import javax.swing.plaf.synth.SynthLookAndFeel; public class MyButton { JFrame frame = new JFrame("Test Buttons"); JButton jButton = new JButton("JButton"); // 按钮 public MyButton() { frame.setLayout(new FlowLayout()); frame.getContentPane().add(jButton); } public void show() { frame.pack(); frame.show(); } public static void main(String[] args) { MyButton tb = new MyButton(); tb.show(); SynthLookAndFeel slf = new SynthLookAndFeel(); try { slf.load(MyButton.class.getResourceAsStream("mybutton.xml"), MyButton.class); UIManager.setLookAndFeel(slf); } catch (Exception e) { e.printStackTrace(); return; } } }
style:
<synth> <style id="mybutton"> <state> <imagePainter method="buttonBackground" path="mybutton.png" sourceInsets="3 6 12 20" paintCenter="true" stretch="true"/> <insets top="3" left="6" bottom="12" right="20"/> <font name="Aharoni" size="16"/> </state> <property key="Button.margin" type="insets" value="0 0 5 8"/> </style> <bind style="mybutton" type="region" key="Button"/> </synth>
上一篇:Java之JDBC数据库连接
下一篇:java访问资源文件