我正在用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>发布于 2017-09-18 12:50:29
下面是一个示例:
<?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" />如果您使用的是Scene Builder,则应该学习如何使用Properties下的这一节:

您也可以使用CSS样式表来实现这一点。
https://stackoverflow.com/questions/46270959
复制相似问题