【发布时间】:2013-04-21 13:47:04
【问题描述】:
我有一个 JTextPane 声明如下:
JTextPane box = new JTextPane();
JScrollPane scroll = new JScrollPane();
StyledDocument doc = box.getStyledDocument();
scroll.setViewportView(box);
scroll = new JScrollPane(box);
我在其上附加如下文本:
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();
}
}
我还设法轻松地让 JTextPane 根据需要显示图像和组件,但我不知道如何将可点击文本编码到 JTextPane 中。例如,我希望它打印一条消息,上面写着“文件已上传到服务器。Accept *Decline*”,如果用户单击接受或拒绝字符串,则它会执行相应的功能.关于如何有效实现这一点的任何想法?
【问题讨论】: