1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
/* 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
It does not work anymore. 🙁
Whenever I try this I get the following error: “The method setFont(javafx.scene.text.Font) in the type Labeled is not applicable for the arguments (java.awt.Font)”. The fragment that produces this output is this one:
Font miFuente1 = new Font(“Serif”, Font.BOLD, 36);
Label label = new Label();
label.setFont(miFuente1);