更改JButton的外观和感觉
答
有可能是一个更好的办法,但以下实用工具类应为你工作:
import javax.swing.JButton;
import javax.swing.LookAndFeel;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;
public class NimbusButton {
private static LookAndFeel nimbus;
public static JButton generateNimbusButton() {
try {
LookAndFeel current = UIManager.getLookAndFeel(); //capture the current look and feel
if (nimbus == null) { //only initialize Nimbus once
for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
break;
}
}
nimbus = UIManager.getLookAndFeel();
}
else
UIManager.setLookAndFeel(nimbus); //set look and feel to nimbus
JButton button = new JButton(); //create the button
UIManager.setLookAndFeel(current); //return the look and feel to its original state
return button;
}
catch (Exception e) {
e.printStackTrace();
return new JButton();
}
}
}
的generateNimbusButton()方法改变了外观和感觉雨云,创建按钮,然后改变了外观和回想起调用该方法时的情况。