8

Can someone please tell me how to make the text inside a label bold in Java FXML?

 <Label fx:id="LegalLabel"  text= "Legal Information" GridPane.halignment="RIGHT" GridPane.rowIndex="16" />

Thank you.

Delin Mathew
  • 249
  • 3
  • 6
  • 15
  • 1
    Add this in your fxml `style="-fx-font-weight: bold;"` or this in your css stylesheet : `.label { -fx-font-weight: bold;}`. With a light [research](https://docs.oracle.com/javase/8/javafx/api/javafx/scene/doc-files/cssref.html#typefont), you should have found this. – Pagbo Apr 13 '18 at 09:48
  • 2
    @Pagbo Thank you for your answers. :) I had found this and had tried this, but it did not work. No idea why. Then I started to doubt my fxml skills as I'm clearly new to it. Therefore, posted the question. :) – Delin Mathew Apr 13 '18 at 11:18
  • Use [SceneBuilder](http://gluonhq.com/products/scene-builder/) – SedJ601 Apr 13 '18 at 13:18
  • 2
    On my computer Java FX doesn't apply bold style to text with "System" font at all (Java 8u92 32-bit, WinXP). So I have to use "Arial Bold" instead. Maybe it is your case. – oshatrk Apr 13 '18 at 22:54
  • @oshatrk From what I can tell, it _does_ apply the style, but the font doesn't actually change at all. The same goes for italic and italic bold System font. – StaRbUck42 Feb 12 '19 at 20:30

1 Answers1

14

Give this a shot

legalLabel.setStyle("-fx-font-weight: bold;");

or try making your fxml look like this

<Label fx:id="LegalLabel"  text= "Legal Information" GridPane.halignment="RIGHT" GridPane.rowIndex="16">
    <font>
        <Font name="System Bold" size="13.0" />
    </font>
</Label>

Edit: try this: legalLabel.setFont(Font.font("Verdana", FontWeight.BOLD, 12));

Matt
  • 3,052
  • 1
  • 17
  • 30