I have a JTextPane declared like the following:
JTextPane box = new JTextPane();
JScrollPane scroll = new JScrollPane();
StyledDocument doc = box.getStyledDocument();
scroll.setViewportView(box);
scroll = new JScrollPane(box);
And I am appending text to it as follows:
public void appendChatText(String text)
{
try
{
doc.insertString(doc.getLength(), text, null);
box.setAutoscrolls(true);
box.setCaretPosition(box.getDocument().getLength());
}
catch(BadLocationException e)
{
e.printStackTrace();
}
}
I also managed to easily get the JTextPane to display images and components as necessary, but I can't figure out how to code clickable text into a JTextPane. For example, I want it to print a message that says something like, "File uploaded to server. Accept *Decline*" and if the user clicks on the accept or decline strings then it executes the appropriate function. Any ideas on how this could be effectively achieved?