Please have a look at the following code
Form.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;
}
}
Main.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)
{
}
}
}
I am using napkin look and feel here, and I am getting the error keys we didn't overwrite: []
. Why is this? I am not getting the GUI. Please help.
This might help
One thing you can try is the following:
- Don't set the look&feel yet.
- Create your user interface.
- Call setUndecorated(true) on the frame.
- Set the look&feel.
- Call SwingUtilities.updateComponentTreeUI for the frame.
- If necessary, call setUndecorated(false) on the frame.
From
http://www.coderanch.com/t/566070/GUI/java/Error-NapKin-Feel
EDIT:
The message "keys we didn't overwrite: []" Is printed here:
@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);
}
}