代码在FXML文档中设置Anchorpane的背景颜色

5 netbeans javafx scenebuilder

我在javafx中创建一个小应用程序.我想设置一个背景颜色,所以以下是我的FXML代码..我需要如何设置背景颜色

<?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>
Run Code Online (Sandbox Code Playgroud)

Sed*_*ick 12

这是一个例子:

<?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" />
Run Code Online (Sandbox Code Playgroud)

如果您正在使用Scene Builder,您应该学习如何使用此部分Properties:

在此输入图像描述

您还可以使用CSS样式表来完成此任务.