JTextArea ta = new JTextArea(); EditorKit kit = new DefaultEditorKit(); Document doc = ta.getDocument(); Reader reader = new FileReader(filename); kit.read(reader, doc, 0);
JTextArea本身有getDocument public Document getDocument() Fetches the model associated with the editor. This is primarily for the UI to get at the minimal amount of state required to be a text editor. Subclasses will return the actual type of the model which will typically be something that extends Document. Returns: the model
EditorKit kit = new DefaultEditorKit();
Document doc = ta.getDocument();
Reader reader = new FileReader(filename);
kit.read(reader, doc, 0);
public Document getDocument()
Fetches the model associated with the editor. This is primarily for the UI to get at the minimal amount of state required to be a text editor. Subclasses will return the actual type of the model which will typically be something that extends Document. Returns:
the model
和setDocumetn(Document doc)方法,可以用这两个方法。