java新手,遇到一个问题,无论我做什么,我似乎都无法解决,所以任何帮助都将不胜感激。
我有一个 Java 小应用程序,并集成了一个使用 Nimbus 外观的弹出式日历 (WWW)。我的问题是,在第一次调用弹出日历后,我无法为我的 GUI 获得相同的外观和感觉。我有两个选择。要么找到一种方法来重置设置,以便我的 GUI 与以前一样并调用弹出窗口,要么输入一些不确定在哪里(主类)的代码,以便所有 GUI 使用 nimbus 外观。
这是弹出日历的代码
import java.awt.*;
import javax.swing.*;
import javax.swing.UIManager.*;
public class Celendar extends JFrame {
//private JPanel p;
Celendar(){
//super("ColorEditor");
//UIManager.put("nimbusBase", new Color(233,22,22));
//UIManager.put("nimbusBlueGrey", new Color(22,200,150));
//UIManager.put("control", new Color(100,150,200));
try {
for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
break;
}else{
UIManager.setLookAndFeel"com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
}
}
} catch (Exception e) {
// If Nimbus is not available, you can set the GUI to another look and
// feel
}
setLayout(new GridLayout(1,1));
setSize(322,250);
setLocation(500,400);
setResizable(false);
Days d= new Days();
/*----- Here -----*/
//setVisible(true);
//setDefaultCloseOperation(EXIT_ON_CLOSE);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
I THINK HERE IS WHERE I NEED TO INSERT SOME CODE TO GET MY GUI DISPLAYING
BEFORE THECALL TO THE POP UP IS MADE.
/*----------------*/
add(d);
// try{
// //UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
// //UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
// UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
// //UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
// //UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
// //UIManager.setLookAndFeel("com.sun.javax.swing.plaf.metal.MetalLookAndFeel");
// SwingUtilities.updateComponentTreeUI(this);
// }catch(Exception e){System.out.println("error "+e);}
}
}
或者我在哪里插入代码以使我的所有 GUI 都具有 nimbus 的外观和感觉