Change font for JButton in Java
Description
The following code shows how to change font for JButton.
Example
import java.awt.Font;
/*from w w w. ja va 2 s . c om*/
import javax.swing.JButton;
import javax.swing.JFrame;
public class Main extends JFrame {
JButton b = new JButton("Add");
public Main() {
setSize(300, 150);
setDefaultCloseOperation(EXIT_ON_CLOSE);
add(b);
b.setFont(new Font("Dialog", Font.PLAIN, 10));
b.revalidate();
setVisible(true);
}
public static void main(String[] args) {
new Main();
}
}
The code above generates the following result.
Home »
Java Tutorial »
Swing »
Java Tutorial »
Swing »