【问题标题】:How to change JTextPane(JTextArea) font and alignment?如何更改 JTextPane(JTextArea) 字体和对齐方式?
【发布时间】:2012-08-22 02:34:12
【问题描述】:

如何更改 JTextPane 的字体和居中文本。 我试过 textPane.setFont(font);但后来我无法居中文本,我尝试使用

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

,但是我无法更改字体...

【问题讨论】:

  • 看看这个post或者这个one...

标签: java swing


【解决方案1】:

我用这个解决了我的问题:

    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);  

【讨论】:

    猜你喜欢
    • 2013-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多