1
我想在我的應用程序中使用nimbus按鈕樣式。我不想改變L & F.只更改按鈕的L & F使用靈氣L & F.有沒有辦法做到這一點?更改JButton的外觀和感覺
我想在我的應用程序中使用nimbus按鈕樣式。我不想改變L & F.只更改按鈕的L & F使用靈氣L & F.有沒有辦法做到這一點?更改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()方法改變了外觀和感覺雨雲,創建按鈕,然後改變了外觀和回想起調用該方法時的情況。