Changing javafx button color on click?

后端 未结 2 1072
隐瞒了意图╮
隐瞒了意图╮ 2021-01-06 08:00

I know I can set a color by using the pressed pseudo selector:

myButton:pressed{}

Problem is, im trying to do this in code by overriding th

2条回答
  •  情歌与酒
    2021-01-06 08:16

    Styling FX Buttons with CSS show some applicable style options for a button.

    "fx-background-color" is just a typo. It needs to be "-fx-background-color".

    To use the styles you need to get the style names and values correct and separate them with semicola. The following approach does this systematically:

      String bstyle=String.format("-fx-text-fill: %s;-fx-fill: %s;-fx-background-color: %s;",textFill,fill, bgColor);
      button.setStyle(bstyle);
    

提交回复
热议问题