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;
}

      

enter image description here

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.

+3


source to share


2 answers


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?

+5


source


for arrayLists on javaFX, try changing the colors on click in CSS:



.list-cell: selected {-fx-background-color: yellow; }

+1


source







All Articles