Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在我的JavaFx应用程序上随机按Enter键会触发错误的按钮操作_Java_Javafx_Javafx 8 - Fatal编程技术网

在我的JavaFx应用程序上随机按Enter键会触发错误的按钮操作

在我的JavaFx应用程序上随机按Enter键会触发错误的按钮操作,java,javafx,javafx-8,Java,Javafx,Javafx 8,在我的javaFx应用程序上按Enter键会触发错误的按钮, 在这种情况下,它会触发注销按钮 到底是什么问题 FXML摘录 <VBox layoutX="7.0" layoutY="160.0" prefHeight="407.0" prefWidth="174.0" AnchorPane.bottomAnchor="0.0" AnchorPane.topAnchor="160.0"> <children> <Button mnemonicParsing

在我的javaFx应用程序上按Enter键会触发错误的按钮, 在这种情况下,它会触发注销按钮 到底是什么问题

FXML摘录

<VBox layoutX="7.0" layoutY="160.0" prefHeight="407.0" prefWidth="174.0" AnchorPane.bottomAnchor="0.0" AnchorPane.topAnchor="160.0">
  <children>
    <Button mnemonicParsing="false" prefHeight="26.0" prefWidth="180.0" text="Add Account" textFill="#c94949" underline="true" />
    <Button defaultButton="true" layoutX="10.0" layoutY="10.0" mnemonicParsing="false" prefHeight="26.0" prefWidth="180.0" text="Account List" textAlignment="CENTER" underline="true" wrapText="true">
    <VBox.margin>
    <Insets top="10.0" />
     </VBox.margin>
    </Button>
    <Button fx:id="logoutButton" onAction="#logoutButtonAccount" defaultButton="true" layoutX="10.0" layoutY="10.0" mnemonicParsing="false" prefHeight="26.0" prefWidth="180.0" text="Logout" textAlignment="CENTER" underline="true" wrapText="true">
    <VBox.margin>
   <Insets top="10.0" />
  </VBox.margin>
  </Button>
  </children>
  </VBox>
但在我的应用程序上随机按enter键会触发此操作并注销该应用程序。非常感谢您的帮助或建议

我试着打印出事件源,但仍然说它是从logoutButton来的

输出:

Button[id=logoutButton, styleClass=button]'Logout'
Button[id=logoutButton, styleClass=button]'Logout'
Button[id=logoutButton, styleClass=button]'Logout'
Button[id=logoutButton, styleClass=button]'Logout'
这些是多次按enter键而不单击按钮后的结果。
提前感谢您的建议或建议。

属性值defaultButton=“true”是导致此问题的原因

将其更改为false或消除该属性将解决该问题

    <Button fx:id="logoutButton" onAction="#logoutButtonAccount" defaultButton="false" layoutX="10.0" layoutY="10.0" mnemonicParsing="false" prefHeight="26.0" prefWidth="180.0" text="Logout" textAlignment="CENTER" underline="true" wrapText="true">

 <VBox.margin>
    <Insets top="10.0" />
 </VBox.margin>

</Button>


正如@zlakad所注意到的。

属性值defaultButton=“true”是导致它的原因

将其更改为false或消除该属性将解决该问题

    <Button fx:id="logoutButton" onAction="#logoutButtonAccount" defaultButton="false" layoutX="10.0" layoutY="10.0" mnemonicParsing="false" prefHeight="26.0" prefWidth="180.0" text="Logout" textAlignment="CENTER" underline="true" wrapText="true">

 <VBox.margin>
    <Insets top="10.0" />
 </VBox.margin>

</Button>


正如@zlakad所注意到的。

TL;DR在我看来,您的按钮设置为默认值,因此每当您按enter键时,都会调用
logoutButtonAccount
。谢谢@zlakad。成功了!让我把这篇文章标为已回答继续,祝你好运。。。我真的不在乎名声;DR在我看来,您的按钮设置为默认值,因此每当您按enter键时,都会调用
logoutButtonAccount
。谢谢@zlakad。成功了!让我把这篇文章标为已回答继续,祝你好运。。。我真的不在乎名声。