Change JButton Font in Java
Description
The following code shows how to change JButton Font.
Example
/* w ww . j av a2s . com*/
import java.awt.BorderLayout;
import java.awt.Font;
import javax.swing.JButton;
import javax.swing.JFrame;
public class Main {
public static void main(String args[]) {
JFrame f = new JFrame("JColorChooser Sample");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JButton button = new JButton("java2s.com");
Font myFont = new Font("Serif", Font.ITALIC, 12);
button.setFont(myFont);
f.add(button, BorderLayout.CENTER);
f.setSize(300, 200);
f.setVisible(true);
}
}
The code above generates the following result.
Home »
Java Tutorial »
Swing »
Java Tutorial »
Swing »