0
我试图将此属性应用于位于GridPane内部的按钮。 GridPane有一个类,所以我尝试了#id.class selector
。这没有奏效。 另外我查了另一个CSS属性:-fx-alignment: bottom-right
。 它的工作! 我试过代码:JavaFX - 应用于按钮的-fx背景颜色不起作用
#grid1 .button {
-fx-background-color: #ff2117;
}
和
#grid1 .button {
-fx-background-color: #ff2117;
}
没有被改变。 我使用IntelliJ IDEA 14和JavaFX版本是8.0.25和IDE的默认设置。
<GridPane fx:id="grid1" alignment="CENTER" hgap="10.0" layoutY="150.0" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="250.0" prefWidth="600.0" style="-fx-background-color: #e6e6e6;" vgap="5.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="120.0" minWidth="0.0" prefWidth="120.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="569.0" minWidth="10.0" prefWidth="454.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="569.0" minWidth="10.0" prefWidth="454.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="569.0" minWidth="10.0" prefWidth="454.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="569.0" minWidth="10.0" prefWidth="454.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="569.0" minWidth="10.0" prefWidth="454.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="10.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="10.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="10.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="10.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="10.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Button fx:id="button1" alignment="CENTER" contentDisplay="CENTER" mnemonicParsing="false" prefHeight="50.0" prefWidth="111.0" style="-fx-background-color: #87cefa; -fx-border-radius: 10;" GridPane.columnIndex="1" />
<Button alignment="CENTER" contentDisplay="CENTER" mnemonicParsing="false" prefHeight="50.0" prefWidth="111.0" style="-fx-background-color: #87cefa; -fx-border-radius: 10;" GridPane.columnIndex="2" />
<Button alignment="CENTER" contentDisplay="CENTER" mnemonicParsing="false" prefHeight="50.0" prefWidth="111.0" style="-fx-background-color: #87cefa; -fx-border-radius: 10;" GridPane.columnIndex="3" />
<Button alignment="CENTER" contentDisplay="CENTER" mnemonicParsing="false" prefHeight="50.0" prefWidth="111.0" style="-fx-background-color: #87cefa; -fx-border-radius: 10;" GridPane.columnIndex="4" />
<Button alignment="CENTER" contentDisplay="CENTER" mnemonicParsing="false" prefHeight="50.0" prefWidth="111.0" style="-fx-background-color: #87cefa; -fx-border-radius: 10;" GridPane.columnIndex="5" />
<Button alignment="CENTER" contentDisplay="CENTER" mnemonicParsing="false" prefHeight="50.0" prefWidth="111.0" style="-fx-background-color: #87cefa; -fx-border-radius: 10;" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<Button alignment="CENTER" contentDisplay="CENTER" mnemonicParsing="false" prefHeight="50.0" prefWidth="111.0" style="-fx-background-color: #87cefa; -fx-border-radius: 10;" GridPane.columnIndex="2" GridPane.rowIndex="1" />
<Button alignment="CENTER" contentDisplay="CENTER" mnemonicParsing="false" prefHeight="50.0" prefWidth="111.0" style="-fx-background-color: #87cefa; -fx-border-radius: 10;" GridPane.columnIndex="3" GridPane.rowIndex="1" />
<Button alignment="CENTER" contentDisplay="CENTER" mnemonicParsing="false" prefHeight="50.0" prefWidth="111.0" style="-fx-background-color: #87cefa; -fx-border-radius: 10;" GridPane.columnIndex="4" GridPane.rowIndex="1" />
<Button alignment="CENTER" contentDisplay="CENTER" mnemonicParsing="false" prefHeight="50.0" prefWidth="111.0" style="-fx-background-color: #87cefa; -fx-border-radius: 10;" GridPane.columnIndex="5" GridPane.rowIndex="1" />
<Button alignment="CENTER" contentDisplay="CENTER" mnemonicParsing="false" prefHeight="50.0" prefWidth="111.0" style="-fx-background-color: #87cefa; -fx-border-radius: 10;" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<Button alignment="CENTER" contentDisplay="CENTER" mnemonicParsing="false" prefHeight="50.0" prefWidth="111.0" style="-fx-background-color: #87cefa; -fx-border-radius: 10;" GridPane.columnIndex="2" GridPane.rowIndex="2" />
<Button alignment="CENTER" contentDisplay="CENTER" mnemonicParsing="false" prefHeight="50.0" prefWidth="111.0" style="-fx-background-color: #87cefa; -fx-border-radius: 10;" GridPane.columnIndex="3" GridPane.rowIndex="2" />
<Button alignment="CENTER" contentDisplay="CENTER" mnemonicParsing="false" prefHeight="50.0" prefWidth="111.0" style="-fx-background-color: #87cefa; -fx-border-radius: 10;" GridPane.columnIndex="4" GridPane.rowIndex="2" />
<Button alignment="CENTER" contentDisplay="CENTER" mnemonicParsing="false" prefHeight="50.0" prefWidth="111.0" style="-fx-background-color: #87cefa; -fx-border-radius: 10;" GridPane.columnIndex="5" GridPane.rowIndex="2" />
<Button alignment="CENTER" contentDisplay="CENTER" mnemonicParsing="false" prefHeight="50.0" prefWidth="111.0" style="-fx-background-color: #87cefa; -fx-border-radius: 10;" GridPane.columnIndex="1" GridPane.rowIndex="3" />
<Button alignment="CENTER" contentDisplay="CENTER" mnemonicParsing="false" prefHeight="50.0" prefWidth="111.0" style="-fx-background-color: #87cefa; -fx-border-radius: 10;" GridPane.columnIndex="2" GridPane.rowIndex="3" />
<Button alignment="CENTER" contentDisplay="CENTER" mnemonicParsing="false" prefHeight="50.0" prefWidth="111.0" style="-fx-background-color: #87cefa; -fx-border-radius: 10;" GridPane.columnIndex="3" GridPane.rowIndex="3" />
<Button alignment="CENTER" contentDisplay="CENTER" mnemonicParsing="false" prefHeight="50.0" prefWidth="111.0" style="-fx-background-color: #87cefa; -fx-border-radius: 10;" GridPane.columnIndex="4" GridPane.rowIndex="3" />
<Button alignment="CENTER" contentDisplay="CENTER" mnemonicParsing="false" prefHeight="50.0" prefWidth="111.0" style="-fx-background-color: #87cefa; -fx-border-radius: 10;" GridPane.columnIndex="5" GridPane.rowIndex="3" />
<Button alignment="CENTER" contentDisplay="CENTER" mnemonicParsing="false" prefHeight="50.0" prefWidth="111.0" style="-fx-background-color: #87cefa; -fx-border-radius: 10;" GridPane.columnIndex="1" GridPane.rowIndex="4" />
<Button alignment="CENTER" contentDisplay="CENTER" mnemonicParsing="false" prefHeight="50.0" prefWidth="111.0" style="-fx-background-color: #87cefa; -fx-border-radius: 10;" GridPane.columnIndex="2" GridPane.rowIndex="2" />
<Button alignment="CENTER" contentDisplay="CENTER" mnemonicParsing="false" prefHeight="50.0" prefWidth="111.0" style="-fx-background-color: #87cefa; -fx-border-radius: 10;" GridPane.columnIndex="2" GridPane.rowIndex="4" />
<Button alignment="CENTER" contentDisplay="CENTER" mnemonicParsing="false" prefHeight="50.0" prefWidth="111.0" style="-fx-background-color: #87cefa; -fx-border-radius: 10;" GridPane.columnIndex="3" GridPane.rowIndex="4" />
<Button alignment="CENTER" contentDisplay="CENTER" mnemonicParsing="false" prefHeight="50.0" prefWidth="111.0" style="-fx-background-color: #87cefa; -fx-border-radius: 10;" GridPane.columnIndex="4" GridPane.rowIndex="4" />
<Button alignment="CENTER" contentDisplay="CENTER" mnemonicParsing="false" prefHeight="50.0" prefWidth="111.0" style="-fx-background-color: #87cefa; -fx-border-radius: 10;" GridPane.columnIndex="5" GridPane.rowIndex="4" />
</children>
</GridPane>
我做我通过场景生成器2.0: – 2014-11-07 15:16:19
是的,这是因为现场建设者的),但是为什么呢?愚蠢的建筑师和我:))。 – 2014-11-07 15:19:55
我只是想在构建和设计Scene Builder中的.fxml文件之后进行悬停......但是,谢谢回复! ) – 2014-11-07 15:21:57