In the example that you linked to you, you will find some tips on what you are trying to do.
Line
StyleConstants.setFontSize(attrs, font.getSize());
resizes the font of the JTextPane and sets its font size, which you pass as a parameter to this method. What do you want to set to a new size based on the current size.
int size = StyleConstants.getFontSize(attrs);
StyleConstants.setFontSize(attrs, size * 2);
This will result in a double JTextPane font size. You could, of course, grow more slowly.
Now you need a button that will call your method.
JButton b1 = new JButton("Increase");
b1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
increaseJTextPaneFont(text);
}
});
So you can write a method similar to the one in the following example:
public static void increaseJTextPaneFont(JTextPane jtp) {
MutableAttributeSet attrs = jtp.getInputAttributes();
int size = StyleConstants.getFontSize(attrs);
StyleConstants.setFontSize(attrs, size * 2);
StyledDocument doc = jtp.getStyledDocument();
doc.setCharacterAttributes(0, doc.getLength() + 1, attrs, false);
}
source
share