JAVA部份[code=java]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;
}
}
}[/code]XML部份[code=xml]<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>[/code] |
|