Change Text Font Of Label Example
- /*
- Change Text Font Of Label Example
- This java example shows how to change font of a label using
- setFont method.
- */
- import java.applet.Applet;
- import java.awt.Label;
- import java.awt.Font;
- /*
- <applet code="ChangeLabelFont" width=100 height=200>
- </applet>
- */
- public class ChangeLabelFont extends Applet{
- public void init(){
- //create labels
- Label label1 = new Label("Label 1");
- Label label2 = new Label("Label 2");
- //add labels
- add(label1);
- add(label2);
- /*
- * To change font of a label use
- * setFont(Font f) method.
- */
- Font myFont = new Font("Serif",Font.BOLD,12);
- label1.setFont(myFont);
- }
- }
Example Output




