Java 在JTextPane中不使用HTML进行换行
我已经在这里和其他Java论坛搜索了一段时间。也在谷歌上搜索,但我没有找到任何符合我期望的东西(基本上是断线)。我做到了这一点:Java 在JTextPane中不使用HTML进行换行,java,swing,line-breaks,Java,Swing,Line Breaks,我已经在这里和其他Java论坛搜索了一段时间。也在谷歌上搜索,但我没有找到任何符合我期望的东西(基本上是断线)。我做到了这一点: public final void messageRoom (String message, Boolean bold, Color color) { StyledDocument document = new DefaultStyledDocument(); SimpleAttributeSet attributes = new SimpleAtt
public final void messageRoom (String message, Boolean bold, Color color) {
StyledDocument document = new DefaultStyledDocument();
SimpleAttributeSet attributes = new SimpleAttributeSet();
if(bold) {
attributes.addAttribute(StyleConstants.CharacterConstants.Bold, Boolean.TRUE);
}
attributes.addAttribute(StyleConstants.CharacterConstants.Foreground, color);
try {
document.insertString(document.getLength(), message, attributes);
} catch (BadLocationException ex) {
System.out.println("ex");
}
chatArea.setStyledDocument(document);
}
这允许我向正在创建的聊天室发送消息,我如何才能使线路中断以转到下一行
谢谢大家!!(类似但不平等的职位:和)
我怎样才能使线路中断,转到下一条线路
也许我不明白这个问题。文本窗格中的文本将自动“换行”
如果试图在新行上开始每条消息,则只需使用“\n”作为新行字符
可能是这样的:
document.insertString(document.getLength(), "\n" + message, attributes);
当然,您不希望为第一条消息添加新行
公共最终无效消息室(字符串消息,布尔粗体,彩色)
当基本变量可以使用时,不要使用对象。只需使用一个“布尔”参数。StackOverflow不是这样工作的。作为一个问题,你不只是发布你发现的很酷的东西。在你的问题中,用代码示例等清楚、简洁地描述问题。如果你也有答案,把它作为答案贴出来,与问题分开,然后在要求的延迟后,接受你的答案。我们不会在标题中加上“已解决”,也不会在问题中加上答案。请访问并阅读和。