-2

'Here is the code I used to change the color when I click the button'

    Button button = new Button("one person");
    button_1p.setStyle("-fx-background-color: #ff0000");
  • 1
    `button_1p.setStyle("")`? – James_D May 17 '22 at 17:30
  • hello , there are many states can we change styles in nodes . when the mouse cursor is overlaping button , when is pressed , released , armed ... can you explain further ? anyway . here is a question when mouse is [hover button](https://stackoverflow.com/questions/61887557/javafx-button-hover/61895784#61895784) – Giovanni Contreras May 17 '22 at 17:41
  • 4
    Probably the best solution for this is to use a custom CSS [pseudoclass](https://openjfx.io/javadoc/17/javafx.graphics/javafx/css/PseudoClass.html), and set the style in an external style sheet. – James_D May 17 '22 at 18:01
  • 1
    Incidental: you might want to consider setting the `-fx-base` looked up color on the button rather than the `-fx-background-color` as it might give you a nicer look. – jewelsea May 17 '22 at 19:37
  • 1
    [Psuedo-class example](https://stackoverflow.com/questions/36094736/change-javafx-style-class-based-on-model-state). – jewelsea May 17 '22 at 19:39
  • stick to java naming conventions please – kleopatra May 18 '22 at 08:21

0 Answers0