Increasing/Decreasing Font Size inside textArea using JButton
17,504
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) );
Comments
-
Sobiaholic almost 2 years
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)); } }