| getSelectedText | back to summary
|
|---|
| public String getSelectedText() Overrides javax.swing.text.JTextComponent.getSelectedText.
Override getSelectedText so that elements produce \n when
text is copied out of the window.
|
| setText | back to summary
|
|---|
| public void setText(String text) Overrides javax.swing.JEditorPane.setText.
Doc from javax.swing.JEditorPane.setText.
Sets the text of this TextComponent to the specified
content,
which is expected to be in the format of the content type of
this editor. For example, if the type is set to text/html
the string should be specified in terms of HTML.
This is implemented to remove the contents of the current document,
and replace them by parsing the given string using the current
EditorKit. This gives the semantics of the
superclass by not changing
out the model, while supporting the content type currently set on
this component. The assumption is that the previous content is
relatively
small, and that the previous content doesn't have side effects.
Both of those assumptions can be violated and cause undesirable results.
To avoid this, create a new document,
getEditorKit().createDefaultDocument(), and replace the
existing Document with the new one. You are then assured the
previous Document won't have any lingering state.
-
Leaving the existing model in place means that the old view will be
torn down, and a new view created, where replacing the document would
avoid the tear down of the old view.
-
Some formats (such as HTML) can install things into the document that
can influence future contents. HTML can have style information embedded
that would influence the next content installed unexpectedly.
An alternative way to load this component with a string would be to
create a StringReader and call the read method. In this case the model
would be replaced after it was initialized with the contents of the
string.
|