![](/img/trans.png)
[英]VSTO Outlook Explorer BeforeMinimize, BeforeMaximize events won't fire
[英]JavaFX: default button won't fire events
在我的代碼中,我將按鈕的defaultProperty綁定到其他一些屬性,例如:
BooleanBinding isAddResourceButtonDefault
= resourceNameTextField.focusedProperty().or(
resourceTypeComboBox.focusedProperty()).or(
divisibleResourceCheckbox.focusedProperty().or(
maxInstancesTextField.focusedProperty()).or(
addResourceButton.focusedProperty()));
addResourceButton.defaultButtonProperty().bind(isAddResourceButtonDefault);
問題在於,addResourceButton絕對不會在按下Enter鍵時觸發任何事件-OnAction和OnKeyPressed都不會。
默認屬性設置得很好-我仔細檢查了一下(使用輸出和ScenicView)。 ScenicView也不會顯示任何在按下鍵時觸發的事件。 有任何想法嗎?
我相信TextField
(和其他TextInputControl
)處理並消耗它們上發生的鍵事件。 因此,在文本字段上按Enter不會在默認按鈕上觸發操作事件(因為鍵事件永遠不會到達Scene
)。
如果您只是想在文本字段之一中按下Enter鍵時觸發按鈕的動作事件處理程序,只需將相同的事件處理程序添加到文本字段中即可。 例如
EventHandler<ActionEvent> addResourceHandler = event -> {
System.out.println("Add resource");
// ...
};
addResourceButton.setOnAction(addResourceHandler);
resourceNameTextField.setOnAction(addResourceHandler);
maxInstancesTextField.setOnAction(addResourceHandler);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.