Java NimbusLookAndFeel无法解析为变量

Java NimbusLookAndFeel无法解析为变量,java,swing,awt,nimbus,Java,Swing,Awt,Nimbus,我正在尝试使用swing学习基本的GUI。 当我尝试激活/设置nimbus时,显示以下错误:“com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel无法解析为变量”。 错误显示在setLookAndFeel()方法中的com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel行中。 我正在使用java build 1.7.0 import java.awt.FlowLayout; import javax.swing

我正在尝试使用swing学习基本的GUI。 当我尝试激活/设置nimbus时,显示以下错误:“com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel无法解析为变量”。 错误显示在setLookAndFeel()方法中的com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel行中。 我正在使用java build 1.7.0

import java.awt.FlowLayout;
import javax.swing.UIManager.LookAndFeelInfo;
import javax.swing.*;

public class swing1 extends JFrame {
    public swing1(){
        super("Title: Swing Project 1");
        //setLookAndFeel();
        setSize(225,80);
        setLookAndFeel();
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        FlowLayout flo = new FlowLayout();
        JButton adds = new JButton ("Add");
        JButton minus = new JButton("Substract");
        JButton mult = new JButton ("Multiply");
        add(adds);
        add(minus);
        add(mult);
        setVisible(true);                   
    }

    private void setLookAndFeel() {
        // TODO Auto-generated method stub
        try {
            UIManager.setLookAndFeel(“com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel”);
        }
        catch (Exception exc) {
            //ignore
        }       
    }

    public static void main (String args   []){
        swing1 startSwing = new swing1();
    }
}
使用常规引号

"com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"
而不是

“com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel”
使用常规引号

"com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"
而不是

“com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel”

定义的文本字符串,而不是用

还可以使用此代码设置外观

import javax.swing.UIManager.*;

try {
    for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
        if ("Nimbus".equals(info.getName())) {
            UIManager.setLookAndFeel(info.getClassName());
            break;
        }
    }
} catch (Exception e) {
    // If Nimbus is not available, you can set the GUI to another look and feel.
}
来自官方

版本说明:不要通过 调用UIManager.setLookAndFeel方法,因为不是所有版本 或者JavaSE6的实现支持Nimbus 在JDK 6更新10和更新10之间,Nimbus包的位置发生了更改 JDK 7发行版。遍历所有已安装的外观 实现是一种更稳健的方法,因为如果Nimbus不 可用时,使用默认的外观。对于JDK 6更新10 发布时,Nimbus软件包位于 com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel


定义的文本字符串,而不是用

还可以使用此代码设置外观

import javax.swing.UIManager.*;

try {
    for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
        if ("Nimbus".equals(info.getName())) {
            UIManager.setLookAndFeel(info.getClassName());
            break;
        }
    }
} catch (Exception e) {
    // If Nimbus is not available, you can set the GUI to another look and feel.
}
来自官方

版本说明:不要通过 调用UIManager.setLookAndFeel方法,因为不是所有版本 或者JavaSE6的实现支持Nimbus 在JDK 6更新10和更新10之间,Nimbus包的位置发生了更改 JDK 7发行版。遍历所有已安装的外观 实现是一种更稳健的方法,因为如果Nimbus不 可用时,使用默认的外观。对于JDK 6更新10 发布时,Nimbus软件包位于 com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel


如果您阅读位于的文档,您将看到在Java 6和Java 7的版本之间,Nimbus外观包的位置发生了更改。建议将外观设置为Nimbus的方法如下:

import javax.swing.UIManager.*;

try {
    for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
        if ("Nimbus".equals(info.getName())) {
            UIManager.setLookAndFeel(info.getClassName());
            break;
        }
    }
} catch (Exception e) {
    // If Nimbus is not available, you can set the GUI to another look and feel.
}

如果您阅读位于的文档,您将看到在Java 6和Java 7的版本之间,Nimbus外观包的位置发生了更改。建议将外观设置为Nimbus的方法如下:

import javax.swing.UIManager.*;

try {
    for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
        if ("Nimbus".equals(info.getName())) {
            UIManager.setLookAndFeel(info.getClassName());
            break;
        }
    }
} catch (Exception e) {
    // If Nimbus is not available, you can set the GUI to another look and feel.
}

这就是我设置Nimbus的方式

import javax.swing.UIManager.LookAndFeelInfo;
import java.awt.EventQueue;
import java.awt.BorderLayout;
import javax.swing.*;
public class Frame1 {
    private JFrame frame;
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {

                     for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
                            if ("Nimbus".equals(info.getName())) {
                                UIManager.setLookAndFeel(info.getClassName());
                                break;
                            }
                        }
                Frame1 window = new Frame1();
                    window.frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

这就是我设置Nimbus的方式

import javax.swing.UIManager.LookAndFeelInfo;
import java.awt.EventQueue;
import java.awt.BorderLayout;
import javax.swing.*;
public class Frame1 {
    private JFrame frame;
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {

                     for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
                            if ("Nimbus".equals(info.getName())) {
                                UIManager.setLookAndFeel(info.getClassName());
                                break;
                            }
                        }
                Frame1 window = new Frame1();
                    window.frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

您应该单击答案旁边的复选标记,将问题标记为已解决。您应该单击答案旁边的复选标记,将问题标记为已解决。