| |
16. 23. 5. To change the size and/or style of a font, you call its deriveFont() method |
|
- deriveFont(int Style): Creates a new Font object with the style specified - one of PLAIN, BOLD, ITALIC, or BOLD+ITALIC
- deriveFont(float size): Creates a new Font object with the size specified
- deriveFont(int Style, float size): Creates a new Font object with the style and size specified
|
import java.awt.BorderLayout;
import java.awt.Font;
import javax.swing.JButton;
import javax.swing.JFrame;
public class DrivedFont {
public static void main(String args[]) {
JFrame f = new JFrame("JColorChooser Sample");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JButton button = new JButton("Pick to Change Background");
Font myFont = new Font("Serif", Font.ITALIC | Font.BOLD, 12);
Font newFont = myFont.deriveFont(50F);
button.setFont(newFont);
f.add(button, BorderLayout.CENTER);
f.setSize(300, 200);
f.setVisible(true);
}
}
|
|
|