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 Styling

Dominik Huber
Dominik Huber
4,631 Points

style="-fx-font-family: Papyrus" doesn't get applied to the program

So here is my code:

<?import javafx.geometry.Insets?>
<?import javafx.scene.layout.GridPane?>

<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.text.Text?>
<?import javafx.scene.control.TextField?>
<GridPane fx:controller="sample.Controller"
          xmlns:fx="http://javafx.com/fxml" alignment="center" hgap="10" vgap="10"
          style="-fx-font-family: Something Strange">

    <Text text="Sup" GridPane.rowIndex="0"
          GridPane.columnSpan="2"
          GridPane.halignment="CENTER"/>

    <Label text="First Name:"
           GridPane.rowIndex="1"
           GridPane.columnIndex="0"/>

    <TextField fx:id="firstName" GridPane.rowIndex="1"
               GridPane.columnIndex="1"/>

    <Button text="Say Sup!"
            GridPane.rowIndex="2"
            GridPane.columnIndex="1"
            GridPane.halignment="RIGHT"
            onAction="#handleSaySup"/>

</GridPane>

No matter what I type in after font-family: it doesn't get applied. I figured out that I don't even have this font installed on my windows 10. So I tried out othre fonts even downoaded custom fonts but no matter it doesn't get applied. Do I have to put in a src first? Or is something wrong with my path?

If you need any information plz say so.

Thx for help!

5 Answers

Anuraag Mishra
PLUS
Anuraag Mishra
Courses Plus Student 4,286 Points

Faced Same Problem, This course was going Flawlessly till now, BrainStormed, then remembered i faced the similar problem while doing some CSS work while back.

SOLUTION: just put Family name in single inverted comma like 'Arial' or 'Papyrus' or 'Comin Sans MS'. style="-fx-font-family: 'Comic Sans MS'"

Papyrus may not work in windows as it does not come pre-installed on windows.

Philipp Räse
Philipp Räse
Courses Plus Student 10,298 Points

Thanks a lot for your answer!

The high-comma-thing blew all my font-problems away!

Dominik Huber
Dominik Huber
4,631 Points

Hi thx for your answer:

Problem is the last post in there "I am on windows and I still can't change the font. Papyrus, Algerian, Ariel, comicsans nothing works :(" is exactly my problem. And nobody answers that. No matter what I put in as font it doesn't get applied.

It is not just the font-family. If you try to set the color to AQUA, or RED, that does not work either! On the GridPane that is. It does work on the Text! But changing the font-size on the GridPane does work! Some attributes work on the GridPane and some don't! I am using version 8 of JDK and Debian Jessie.