Search code examples
javajavafxjavafx-8

How do I create a bigger font in Java FX


I'm currently assigned to help with a project to create a system for scheduling, I don't have a lot of experience with Java FX so I was wondering if someone can help me with this.

I'm trying to make the font of the Administrator log in bigger. Here is the code.

@Override
public Region getView() {
    VBox content = new VBox(72);
    content.setId("center");
    content.setAlignment(Pos.CENTER);



    Label message = new Label("Administrator Log In");


    JFXButton ok = new JFXButton("OK");
    ok.setGraphic(FontAwesome.getFontAwesomeLabel(FontAwesome.CHECK, 72));
    ok.setButtonType(ButtonType.RAISED);

    content.getChildren().addAll(message,ok);

    return content;
}

Solution

  • From the doc (Oracle Doc), there is different ways :

    • Use a constructor of the Font class

      label1.setFont(new Font(30));
      label1.setFont(new Font("Arial", 30));
      
    • Use a static method of the Font class

      label2.setFont(Font.font(32));
      label2.setFont(Font.font("Cambria", 32));
      

    There is others constructor in the Font class : Documentation