So I have a socket connected and constantly reading from a server. I have no problem printing lines to the terminal as they arrive, but I’m struggling with Swing. I want to add each line to the display as it comes in, with certain pre-defined words highlighted. I looked at JEditPane, and the only way I could see would be setText(getText()+newText), which I looked at and thought it looked very wrong. I had a look at the Document classes, and none of them seems to have an obvious append method. Am I missing something obvious, or is there an easy way to do this with another component?
So I have a socket connected and constantly reading from a server. I have
Share
One way to address this would be to create a
JTextPanewith aDocumentListenerthat will do your necessary hightlight.Create your text as you get from server and call
insertStringon the text pane’s document. TheinsertStringwould work as append.Check the javadoc out.