JavaFX - 应用于Button的-fx-background-color无效

时间:2014-11-07 02:34:28

标签: css javafx

我正在尝试将此属性应用于位于GridPane内部的按钮。 GridPane有一个类,所以我尝试了#id.class selector。它不起作用。 我还检查了另一个css属性:-fx-alignment: bottom-right。 它奏效了! 我尝试了代码:

#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>

1 个答案:

答案 0 :(得分:1)

我认为问题是你设置的FXML风格=“ - fx-background-color:#87cefa;”因此,当您使用css文件更改样式表时,样式仍为...