JFXButton 看起来在启动后立即被点击

JFXButton looks clicked right after start

我的一个菜单按钮(左)在开始后看起来已经被点击或突出显示。

我还没有为这些按钮附加任何操作,所以当我点击这个按钮时,一切都开始看起来像它应该的那样

三个按钮看起来都一样:

  <JFXButton layoutX="14.0" layoutY="122.0" prefHeight="48.0" prefWidth="101.0" style="-fx-background-color: #f72241; -fx-background-radius: 100;" text="M/M(a,b)/1" textFill="WHITE">
     <font>
        <Font size="15.0" />
     </font>
  </JFXButton>
  <JFXButton layoutX="150.0" layoutY="122.0" prefHeight="48.0" prefWidth="101.0" style="-fx-background-color: #f72241; -fx-background-radius: 100;" text="M/M(a,b)/c" textFill="WHITE">
     <font>
        <Font size="15.0" />
     </font>
  </JFXButton>
  <JFXButton layoutX="285.0" layoutY="122.0" prefHeight="48.0" prefWidth="101.0" style="-fx-background-color: #f72241; -fx-background-radius: 100;" text="M/GI(1,s)/1" textFill="WHITE">
     <font>
        <Font size="15.0" />
     </font>
  </JFXButton>

是重点!

有两种解决方法:

为显示的其他内容提供焦点。

button.sceneProperty().addListener((obs, ov, nv) -> {
    if(nv != null)
        nv.requestFocus();
});

或者设置focus traversable为false

button.setFocusTraversable(false);

您也可以在 fxml 中设置可遍历的焦点。