所以這是我的問題。我在我的控制器的初始化(URL,ResourceBundle)函數中有以下代碼。當我點擊某一行時,setOnMouseClicked將被正確調用,但setOnKeyPressed不會。我在這裏錯過了什麼?TableRow不使用setOnKeyPressed
tblView.setRowFactory(tv -> {
TableRow<Entry> row = new TableRow<Entry>();
row.setOnMouseClicked((MouseEvent e) -> {
if ((!row.isEmpty()) && (e.getButton() == MouseButton.PRIMARY) && (e.getClickCount() == 2)) {
openEntryEditor(row);
e.consume();
}
});
row.setOnKeyPressed((KeyEvent e) -> {
if ((!row.isEmpty()) && (e.getCode() == KeyCode.ENTER)) {
openEntryEditor(row);
e.consume();
}
});
return row;
});
有趣。我被Gui誤導了:P。我認爲TableRow具有焦點,因爲它被點擊或移動到箭頭鍵時突出顯示。 – user9985