我正在为我的项目使用 StyledDocument 和 SimpleAttributeSet,但我遇到了 UI 问题。
我要尝试的第一件事是填充,因为背景太“紧”,所以我们看到很多文字而不是很多蓝色,但我不知道如何使蓝色表面更大。
然后,如果我可以应用半径,那将是完美的,但我也无法做到。
这是重现我在第一张图片上的内容所需的代码:
StyledDocument doc = chatBox.getStyledDocument();
SimpleAttributeSet rightO = new SimpleAttributeSet();
StyleConstants.setBackground(rightO, new Color(59,130,247));
StyleConstants.setForeground(rightO, new Color(255,255,255));
StyleConstants.setFontSize(rightO, 14);
SimpleAttributeSet blue = new SimpleAttributeSet();
StyleConstants.setAlignment(blue, StyleConstants.ALIGN_RIGHT);
StyleConstants.setRightIndent(blue, 10);
StyleConstants.setLeftIndent(blue, 100);
try {
doc.insertString(doc.getLength(), "\n"+message.getContent(), rightO);
doc.setParagraphAttributes(doc.getLength() - message.getContent().length(), doc.getLength(), blue, false);
} catch (BadLocationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}