java显示代码大小_java-增加显示HTML文本的JTextPane的字体大小

在链接到的示例中,您将找到有关您要执行的操作的一些线索.

线

StyleConstants.setFontSize(attrs, font.getSize());

更改JTextPane的字体大小并将其设置为您作为参数传递给此方法的字体的大小.您要基于当前大小将其设置为新大小的内容.

//first get the current size of the font

int size = StyleConstants.getFontSize(attrs);

//now increase by 2 (or whatever factor you like)

StyleConstants.setFontSize(attrs, size * 2);

这将导致JTextPane的字体大小加倍.您当然可以较慢的速度增加.

现在,您需要一个按钮来调用您的方法.

JButton b1 = new JButton("Increase");

b1.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e){

increaseJTextPaneFont(text);

}

});

因此,您可以编写类似于示例中的方法:

public static void increaseJTextPaneFont(JTextPane jtp) {

MutableAttributeSet attrs = jtp.getInputAttributes();

//first get the current size of the font

int size = StyleConstants.getFontSize(attrs);

//now increase by 2 (or whatever factor you like)

StyleConstants.setFontSize(attrs, size * 2);

StyledDocument doc = jtp.getStyledDocument();

doc.setCharacterAttributes(0, doc.getLength() + 1, attrs, false);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值