使用JButton增加/减少textArea内的字体大小 [英] Increasing/Decreasing Font Size inside textArea using JButton

查看:161
本文介绍了使用JButton增加/减少textArea内的字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想要做什么:
我想增加每次点击增加尺寸时, textArea 中文本的大小。
我会知道如何做相反的事情。



短代码

  JButton incButton = new JButton(+); 
fontFrame.add(incButton);
incButton.addActionListener(new fontIncAction());
JButton DecButton = new JButton( - );
fontFrame.add(DecButton);

//textArea.setFont(Font(Serif,Font.PLAIN,fz));



private class fontIncAction implements ActionListener {
public void actionPerformed(ActionEvent e){

textArea.setFont(new Font ( 衬线,Font.PLAIN,20));


$ / code $


解决方案

使代码更一般,你可以在你的ActionListener中做如下的事情:
$ b

  Font font = textArea.getFont(); 
float size = font.getSize()+ 1.0f;
textArea.setFont(font.deriveFont(size));


I'm creating a sticky note application using Java.

What I want to do: I want to increase the size of the texts inside textArea each time I click on the increase size. I will know how to do the opposite obviously.

Short Code:

        JButton incButton = new JButton("+");
        fontFrame.add(incButton);
        incButton.addActionListener(new fontIncAction());
        JButton DecButton = new JButton("-");
        fontFrame.add(DecButton);

        //textArea.setFont( Font("Serif", Font.PLAIN, fz));
    }
}

private class fontIncAction implements ActionListener{
    public void actionPerformed(ActionEvent e){

        textArea.setFont(new Font("Serif",Font.PLAIN,20));
    }
}

解决方案

To make the code more general you can do something like the following in your ActionListener:

Font font = textArea.getFont();
float size = font.getSize() + 1.0f;
textArea.setFont( font.deriveFont(size) );

这篇关于使用JButton增加/减少textArea内的字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆