5

I am creating a small application in javafx. I want to set a background color so following is my FXML code .. how I need to set background color

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.text.*?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<AnchorPane id="AnchorPane"  prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="javafxapplication1.FXMLhomepageController">
   <children>
      <Label fx:id="lb1" layoutX="139.0" prefHeight="109.0" prefWidth="343.0" text="home page" textAlignment="JUSTIFY" textFill="#355680">
         <font>
            <Font size="68.0" />
         </font>
      </Label>
   </children>
</AnchorPane>

1 Answers1

17

Here is an example:

<?import javafx.scene.layout.AnchorPane?>

<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" style="-fx-background-color: blue;" xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1" />

If you are using Scene Builder, you should learn how to use this section under Properties:

enter image description here

You can also use a CSS stylesheet to accomplish this.

SedJ601
  • 12,173
  • 3
  • 41
  • 59