2012-08-27 112 views
0

如何更改JTextPane和中心文本的字體。 我試着用textPane.setFont(font);但後來我不能文本居中,我試圖用如何更改JTextPane(JTextArea)字體和對齊方式?

SimpleAttributeSet attribs = new SimpleAttributeSet(); 
    StyleConstants.setAlignment(attribs , StyleConstants.ALIGN_CENTER); 

,但後來我不能改變字體...

+0

看一看這個[ (http://stackoverflow.com/questions/6949125/font-of-a-styleddocument-associated-with-a-jtextpane)或這[一](http://stackoverflow.com/questions/10585956/jtextpane - 如何到組最字體大小)... – aymeric

回答

0

我解決我的問題與此:

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); 
相關問題