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()メソッドは、外観を変更し、ニンバスに感じて、ボタンを作成し、その後、外観を変更し、メソッドが呼び出されたときの状態に戻ります。