Nimbus 设置后返回 GUI

发布于 2024-10-10 16:59:45 字数 2273 浏览 8 评论 0原文

java新手,有一个问题,无论我做什么,我似乎都无法解决,所以任何 帮助将不胜感激。

我有一个 Java 的小应用程序,并集成了一个弹出日历(WWW) 使用 Nimbus 外观和感觉的可用。我的问题是我无法 调用弹出日历后,我的 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 的外观和感觉

New to java and have a problem I cannot seem to fix no matter what I do, so any
help will be greatly appreciated.

I have a little application in Java and have integrated a pop up calendar (WWW)
avaiable which uses the Nimbus look and feel. My problem is that I am unable to
get the same look and feel for my GUI after the pop up calendar gets invoked for
the first time. I have two choices. either to find a way to reset the settings so
that my GUI is as before and call to the pop up are made or to enter some code not
sure where(Main class) so that all the GUI uses the nimbus look and feel.

Here is the code for the pop up calendar

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);}
    }
}

Or where do I insert code to make all my GUI have the nimbus look and feel

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鲜肉鲜肉永远不皱 2024-10-17 16:59:45

如果您希望所有 UI 都具有相同的 L&F,请在创建任何 UI 或组件之前放置设置它的代码;通常就在 main(String[]) 中或在创建的第一个 UI 的构造函数中。完成日历后,您还可以通过调用 UIManager.getSystemLookAndFeelClassName() 来设置 L&F。认为一旦您设置了 L&F,之后创建的所有组件都将获得该 L&F(如果您还不知道)。

If you want all UIs to have the same L&F, put that code that sets it before any UI or component is created; typically right in main(String[]) or in the constructor of your first UI that is created. You could also set the L&F back after you are done with the calendar by calling UIManager.getSystemLookAndFeelClassName(). Think is that once you set the L&F, all components created after that will get that L&F (if you didn't already know that).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文