我正面临 JTextPane 和悬挂缩进的恼人小错误。
这是一个简单的例子:
public class Scrap {
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(200, 200);
frame.setLayout(new BorderLayout());
JTextPane textPane = new JTextPane();
JScrollPane scroll = new JScrollPane(textPane);
frame.add(scroll);
StyledDocument doc = (StyledDocument) textPane.getDocument();
try {
String str = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum ";
doc.insertString(doc.getLength(), str, null);
// Hanging indent
MutableAttributeSet mas = new SimpleAttributeSet();
StyleConstants.setLeftIndent(mas, 20);
StyleConstants.setFirstLineIndent(mas, -20);
doc.setParagraphAttributes(0, str.length(), mas, false);
} catch (BadLocationException e) {
e.printStackTrace();
}
frame.setVisible(true);
frame.setLocationRelativeTo(null);
}
}
在我的计算机上,使用 Java 7,由于某种原因,第一行比其他行更粗......有人知道如何解决这个问题吗?