1

请看下面的代码

表单.java

import java.awt.event.*;
import java.awt.*;
import javax.swing.*;

public class Form extends JFrame
{
    private JButton[]buttonHolder;

    public Form()
    {
        //Intializing instance variables
        buttonHolder = new JButton[9];

        this.add(createCenterPanel());
        this.setSize(300,300);
        this.setVisible(true);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    private JPanel createCenterPanel()
    {
        JPanel centerPanel = new JPanel();
        centerPanel.setLayout(new GridLayout(3,3,0,0));

        for(int i=0;i<9;i++)
        {
            buttonHolder[i] = new JButton();
            centerPanel.add(buttonHolder[i]);
        }

        return centerPanel;
    }
}

主.java

import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import napkin.NapkinLookAndFeel;

public class Main
{
    public static void main(String[]args)
    {
        try
        {
            Form f = new Form();
            UIManager.setLookAndFeel(new NapkinLookAndFeel());
        }
        catch(Exception e)
        {

        }
    }
}

我在这里使用餐巾纸的外观和感觉,但出现错误keys we didn't overwrite: []。为什么是这样?我没有得到 GUI。请帮忙。

4

2 回答 2

3

这可能会有所帮助

您可以尝试的一件事是:

  • 不要设置外观和感觉。
  • 创建您的用户界面。
  • 在框架上调用 setUndecorated(true)。
  • 设置外观。
  • 为框架调用 SwingUtilities.updateComponentTreeUI。
  • 如有必要,请在框架上调用 setUndecorated(false)。

http://www.coderanch.com/t/566070/GUI/java/Error-NapKin-Feel

编辑:

消息“我们没有覆盖的键:[]”打印在这里:

@Override
protected void initClassDefaults(UIDefaults table) {
    super.initClassDefaults(table);
    String cName = NapkinLookAndFeel.class.getName();
    String basicPackageName = cName.replace("NapkinLookAndFeel", "Napkin");
    for (String uiType : UI_TYPES) {
        String uiClass = basicPackageName + uiType;
        table.put(uiType, uiClass);
    }

    Set<Object> keys = new HashSet<Object>(table.keySet());
    keys.removeAll(Arrays.asList(UI_TYPES));
    if (keys.size() != 0) {
        System.out.println("keys we didn't overwrite: " + keys);
    }
}

http://www.jarvana.com/jarvana/view/net/sf/squirrel-sql/thirdparty-non-maven/napkinlaf/1.2/napkinlaf-1.2-sources.jar!/net/sourceforge/napkinlaf/NapkinLookAndFeel.java ?格式=好的

于 2013-03-12T17:36:00.880 回答
0

在创建以下实例之前,首先设置外观和感觉Form

public static void main(String[]args)
{
    try
    {
        UIManager.setLookAndFeel(new NapkinLookAndFeel());
        Form f = new Form();
    }
    catch(Exception e)
    {
        // it's generally a bad idea to silently swallow exceptions,
        // you should at least do...
        e.printStackTrace();
    }
}
于 2013-03-12T19:31:47.523 回答