2011-11-29 63 views
1

是否有可能在DocumentListener中獲取根元素名稱,actionCommand等...。我需要獲取JTextField名稱以跟蹤哪個文本字段被修改。在DocumentEvent中獲取元素名稱

public void insertUpdate(DocumentEvent e) { 
    //something like this 
    e.getName() //helps to keep a track which textfield was modified 
} 

回答

1

javadoc,唯一有趣的事情,你可以得到的是該事件document that sourced the changed event的類型。也許挖getDocument()方法可以幫助你。

+2

是的,遇到http://stackoverflow.com/questions/5774732/how-to-get-jtextfield-name-in-which-is-document-placed – Akash

1

這是不可能的。文檔只是模型。同一個文檔可以在多個JTextComponents中設置。