因为e.getKeyChar()返回Char类型的
所以当然不对了
不如监听Document的Listener

解决方案 »

  1.   

    Document用社么类应用?
    是Panel吗?
    他有社么方法来处理词组输入呢?你能描述的详细写吗
      

  2.   

    楼上的,
    e.getKeyCode()咋return String?
      

  3.   

    Document 类用来管理文本组件中的数据。
    每一个文本组件都对应的有document
    具体的可以查看javax.swing.text.JTextComponent类中的介绍
    调用public Document getDocument()可以得到Document
    Document类有一个方法:public void addDocumentListener(DocumentListener listener 每当文本组件中的内容变化的时候
    都将将事件传输给listener来处理。具体来说定义了下列三个方法
    void changedUpdate(DocumentEvent e) 
              Gives notification that an attribute or set of attributes changed. 
     void insertUpdate(DocumentEvent e) 
              Gives notification that there was an insert into the document. 
     void removeUpdate(DocumentEvent e) 
              Gives notification that a portion of the document has been removed. 其中e是事件
    e有方法:
     Document getDocument() 
              Gets the document that sourced the change event. 
     int getLength() 
              Returns the length of the change. 
    可以得到相关的信息
     而Document 类有String getText(int offset, int length)  返回刚才键入的string
      

  4.   

    谢谢,小蚊子
    可能我没有说清楚:
    我是在一个Panel上实现基本中文编辑器的功能。而不是在文本组件上处理输入字串。
    不管如何,我会放分的。
      

  5.   

    你可以用javax.swing.JTextPane
    或者javax.swing.JEditorPane
      

  6.   

    JTextPane,JEditorPane可以自定义
    Del事件吗?
      

  7.   

    我看了JEdit的程序和源码,
    好象它没用JTextPane和JEditorPane作编辑器的主体.不过它可以输入任意的词汇.
    看看先.