[英]How to change JTextPane(JTextArea) font and alignment?
How to change font of JTextPane and center text. 如何更改JTextPane和中心文本的字体。 I tried with textPane.setFont(font);
我尝试使用textPane.setFont(font); but then i cannot center text and i tried using
但后来我无法使文本居中,我尝试使用
SimpleAttributeSet attribs = new SimpleAttributeSet();
StyleConstants.setAlignment(attribs , StyleConstants.ALIGN_CENTER);
, but then i cannot change font... ,但后来我无法更改字体...
I solved my problem with this: 我用这个解决了我的问题:
StyleContext context = new StyleContext();
StyledDocument document = new DefaultStyledDocument(context);
Style style = context.getStyle(StyleContext.DEFAULT_STYLE);
StyleConstants.setAlignment(style, StyleConstants.ALIGN_CENTER);
JTextPane output = new JTextPane(document);
output.setFont(font);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.