im stuck on a simple question, i want to display formatted text in a swing control and keep on adding new values into it, i don't want to use .setText(.getText + text)
for personal reasons, (something like the append method for text area is what I am looking for) I've tried JEditorpane, Textpane
but all of them do not have append method. Which swing control should I use?
Asked
Active
Viewed 66 times
1

eatSleepCode
- 4,427
- 7
- 44
- 93

Ajinkya Jumbad
- 95
- 1
- 7
-
1What do you mean by *personal reason*? – Anirban Nag 'tintinmj' Jan 04 '14 at 19:21
-
.setText(.getText + text)' for personal reasons, yes you are right have to use Document – mKorbel Jan 04 '14 at 19:23
-
voting to close this question – mKorbel Jan 04 '14 at 19:24
1 Answers
5
While JEditorPane has no append method, you can certainly add text to its Document via its insertString(...)
method, and I suggest that you look into doing this.
Edit
You ask:
it worked it out but it seems it works like setText, all the previous data vanishes.. how do i keep the previous data ?
Are you correctly passing in the first parameter, the offset? This should be the length of the current Document.

Hovercraft Full Of Eels
- 283,665
- 25
- 256
- 373
-
it worked it out but it seems it works like setText, all the previous data vanishes.. how do i keep the previous data ? – Ajinkya Jumbad Jan 04 '14 at 19:30
-
@AjinkyaJumbad: are you correctly passing in the first parameter, the offset? This should be the length of the current Document. – Hovercraft Full Of Eels Jan 04 '14 at 19:32
-