Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Build a JavaFX Application Design a Better App Grids

JavaFx: txt.setFont(new Font("Arial", 30)); is not working on windows 10.

I have tried other fonts too but still they didn't work. And i did not find any solution on the internet. Thank you for your time!

package sample;

import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Group; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.layout.GridPane; import javafx.scene.layout.VBox; import javafx.scene.text.Text; import javafx.stage.Stage;

import java.awt.*;

public class Main extends Application {

@Override
public void start(Stage primaryStage) throws Exception{
    //Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
    Group root = new Group();
    Text txt = new Text("Sup?");
    txt.setFont(new Font("Arial", 30)); // THIS IS THE LINE!!!!
    Label label = new Label("Name:");
    TextField nameFld = new TextField();
    GridPane grid = new GridPane();
    grid.add(label, 0, 0);
    grid.add(nameFld, 1, 0);
    grid.setHgap(20);
    Button btn = new Button();
    grid.add(btn, 1,1);
    //grid.setGridLinesVisible(true);
    btn.setText("Say Sup!");
    btn.setOnAction(event -> System.out.printf("Sup %s!%n",
            nameFld.getText()));
    txt.setY(50);
    VBox box = new VBox();
    box.getChildren().addAll(txt, grid);
    root.getChildren().add(box);
    primaryStage.setTitle("Sup");
    primaryStage.setScene(new Scene(root, 300, 275));
    primaryStage.show();
}


public static void main(String[] args) {
    launch(args);
}

}

And this is the output error generated by the code:

Error:(25, 21) java: no suitable constructor found for Font(java.lang.String,int) constructor java.awt.Font.Font(java.lang.String,int,int) is not applicable (actual and formal argument lists differ in length) constructor java.awt.Font.Font(java.lang.String,int,float) is not applicable (actual and formal argument lists differ in length) constructor java.awt.Font.Font(java.lang.String,int,float,boolean,sun.font.Font2DHandle) is not applicable (actual and formal argument lists differ in length) constructor java.awt.Font.Font(java.io.File,int,boolean,sun.font.CreatedFontTracker) is not applicable (actual and formal argument lists differ in length) constructor java.awt.Font.Font(sun.font.AttributeValues,java.lang.String,int,boolean,sun.font.Font2DHandle) is not applicable (actual and formal argument lists differ in length) constructor java.awt.Font.Font(java.util.Map<? extends java.text.AttributedCharacterIterator.Attribute,?>) is not applicable (actual and formal argument lists differ in length) constructor java.awt.Font.Font(java.awt.Font) is not applicable (actual and formal argument lists differ in length)