我写一个GUI程序时,我加了下面这么两句之后:JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);当我在JFrame窗口中了一个JTextField元件中输入汉字时,抛出异常:Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at java.util.Hashtable.get(Unknown Source)
at javax.swing.KeyboardManager.registerMenuBar(Unknown Source)
at javax.swing.JMenuBar.addNotify(Unknown Source)
at java.awt.Container.addNotify(Unknown Source)
at javax.swing.JComponent.addNotify(Unknown Source)
at javax.swing.plaf.metal.MetalTitlePane.addNotify(Unknown Source)
at java.awt.Container.addNotify(Unknown Source)
at javax.swing.JComponent.addNotify(Unknown Source)
at java.awt.Container.addNotify(Unknown Source)
at javax.swing.JComponent.addNotify(Unknown Source)
at javax.swing.JRootPane.addNotify(Unknown Source)
at java.awt.Container.addNotify(Unknown Source)
at java.awt.Window.addNotify(Unknown Source)
at java.awt.Frame.addNotify(Unknown Source)
at java.awt.Window.pack(Unknown Source)
at sun.awt.im.CompositionArea.<init>(Unknown Source)
at sun.awt.im.CompositionAreaHandler.createCompositionArea(Unknown Sourc
e)
at sun.awt.im.CompositionAreaHandler.inputMethodTextChanged(Unknown Sour
ce)
at sun.awt.im.CompositionAreaHandler.processInputMethodEvent(Unknown Sou
rce)
at sun.awt.im.InputMethodContext.dispatchEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)大家应该知道,在jdk1.4版之后,JAVA加了一个输入法的小窗口,当输入汉字时都会弹出来。
可当我用了下面这两句:
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);后,我在输入汉字时,JAVA自带的输入法小窗口不见了,但抛出了异常。
JDialog.setDefaultLookAndFeelDecorated(true);当我在JFrame窗口中了一个JTextField元件中输入汉字时,抛出异常:Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at java.util.Hashtable.get(Unknown Source)
at javax.swing.KeyboardManager.registerMenuBar(Unknown Source)
at javax.swing.JMenuBar.addNotify(Unknown Source)
at java.awt.Container.addNotify(Unknown Source)
at javax.swing.JComponent.addNotify(Unknown Source)
at javax.swing.plaf.metal.MetalTitlePane.addNotify(Unknown Source)
at java.awt.Container.addNotify(Unknown Source)
at javax.swing.JComponent.addNotify(Unknown Source)
at java.awt.Container.addNotify(Unknown Source)
at javax.swing.JComponent.addNotify(Unknown Source)
at javax.swing.JRootPane.addNotify(Unknown Source)
at java.awt.Container.addNotify(Unknown Source)
at java.awt.Window.addNotify(Unknown Source)
at java.awt.Frame.addNotify(Unknown Source)
at java.awt.Window.pack(Unknown Source)
at sun.awt.im.CompositionArea.<init>(Unknown Source)
at sun.awt.im.CompositionAreaHandler.createCompositionArea(Unknown Sourc
e)
at sun.awt.im.CompositionAreaHandler.inputMethodTextChanged(Unknown Sour
ce)
at sun.awt.im.CompositionAreaHandler.processInputMethodEvent(Unknown Sou
rce)
at sun.awt.im.InputMethodContext.dispatchEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)大家应该知道,在jdk1.4版之后,JAVA加了一个输入法的小窗口,当输入汉字时都会弹出来。
可当我用了下面这两句:
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);后,我在输入汉字时,JAVA自带的输入法小窗口不见了,但抛出了异常。
private JFrame frame = null;
private JDialog d = null; public Test() {
frame = new JFrame("测试窗体");
d = new JDialog(frame, "测试", true); frame.setDefaultLookAndFeelDecorated(true);
d.setDefaultLookAndFeelDecorated(true); JTextArea text = new JTextArea();
d.getContentPane().add(text); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300, 200);
frame.setLocationRelativeTo(null);
frame.setVisible(true); d.setSize(200, 100);
d.setLocationRelativeTo(null);
d.setVisible(true);
} public static void main(String[] args) {
new Test();
}}