简体   繁体   English

JavaFX-应用于Button的-fx-background-color不起作用

[英]JavaFX - -fx-background-color applied to Button is not working

I'm trying to apply this property to the buttons which located inside of the GridPane. 我正在尝试将此属性应用于GridPane内部的按钮。 GridPane has a class so I tried the #id.class selector . GridPane有一个类,所以我尝试了#id.class selector It's not worked. 没用 Also I checked another css property: -fx-alignment: bottom-right . 我也检查了另一个css属性: -fx-alignment: bottom-right It's worked! 工作了! I tried the code: 我尝试了代码:

#grid1 .button {
-fx-background-color: #ff2117;

} }

and

#grid1 .button {
    -fx-background-color: #ff2117;
}

Nothing is changed. 一切都没有改变。 I use IntelliJ IDEA 14 and JavaFX version is 8.0.25 and default settings of IDE. 我使用IntelliJ IDEA 14JavaFX版本是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>

I think that the problem is that you set in FXML style="-fx-background-color: #87cefa;" 我认为问题在于您设置为FXML style =“-fx-background-color:#87cefa;” so when you change the Stylesheet with the css file the style remain ... 因此,当您使用css文件更改样式表时,样式仍然保持...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM