我写一个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自带的输入法小窗口不见了,但抛出了异常。

解决方案 »

  1.   

    我测试了一下,没有异常,你检查其它代码看看,或者是环境的问题?import javax.swing.*;public class Test {
        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();
        }}
      

  2.   

    JAVA自带的输入法小窗口?怎么我一直没有发现的呢?
      

  3.   

    我也遇到过楼主的问题。怎么其他人都没有发现呢?真是奇怪之极。而且我发现极点五笔和Swing窗口有冲突,如果退出时处于极点五笔的状态,就会死掉。