Stylish Button in JavaFX
I have Button
in my FXML
file and I give it the style belowCSS
.button {
-fx-background-color: linear-gradient(#ff5400, #be1d00);
-fx-background-radius: 30;
-fx-background-insets: 0;
-fx-text-fill: white;
}
as you can see the button has a new awesome style, but whenever I click on it, it stays the same as before and you cannot figure out if it is pressed or not ...
When I searched, I found one solution at this link: clicked CSS , but if you notice it is CSS that is used by web browsers and JavaFX don't support it.
so what is the solution? I want my button to change appearance when users click or click on it.
source to share
You need to add psuedoclass state pressed
to you css and add a new css to it that will differentiate your current css button from it when clicked:
.button:pressed {
// Your new css
}
To change the style when hovering the button
using:
.button:hover {
// Your new css
}
For a better understanding of what style you can add to style the button, you can go through How to make a button clicked or selected?
source to share