Java desktop application development learning (X) - css style sheets and change the style to achieve suspension Button

css stylesheets use

css style javafx in with some different html, css javafx in, is -fx-background-colorthe way it is, can refer to specific documentation JavaFx css official documents

javafx in, css styles used in two ways

  • Directly in the fxml
  • fxml reference css file

fxml directly Styles

You can use the style attribute in a control

<Text layoutX="235.0" layoutY="173.0" style="-fx-background-color: black">hello</Text>

It can also be defined directly in the scenebuilder

fxml reference css

Root tag using stylesheets properties of the layout, remember a @symbol

stylesheets="@button.css" 

Button suspension achieve the effect

css file, id foregoing references have to add #, reference tab, then add.

We can use css to achieve pseudo-label

Default slide to the button is green, the mouse, the button turns blue. Click the button, the button turns white, the effect is as follows

.button{
    -fx-background-color: green;
}

.button:hover{
    -fx-background-color: blue;
}


.button:focused{
    -fx-background-color: white;
}

Guess you like

Origin www.cnblogs.com/kexing/p/11105256.html