リンク先の例では、何をしようとしているかの手がかりを見つけることができます。
ライン
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のフォントサイズが2倍になります。あなたはもちろん、より遅い速度で増加することができます。
これで、メソッドを呼び出すボタンが必要になりました。
JButton b1 = new JButton("Increase");
b1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
increaseJTextPaneFont(text);
}
});
だから、このように例では1と同様の方法を記述することができます。彼は、フォントサイズが文書にすでにあったものに比例した規模で増加した」ことを望んでいた
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);
}
。 "しかし、あなたの例では、文書内のすべてのフォントが同じサイズに設定されています。 – ka3ak