我试图在TableView的TableRow上使用KeyEvent处理程序,但处理程序没有被调用。我知道可以在TableView上注册一个处理程序,并使用selectionmodel / focus模型来获取被选中或聚焦的项目,但我想在特定用例的行上注册一个键事件。 onKeyPressed事件的文档说,
Defines a function to be called when this Node or its child Node has input focus and a key has been pressed. The function is called only if the event hasn't been already consumed during its capturing or bubbling phase.
表格行没有得到该事件,因为其他一些节点已经消耗了它?
有没有办法可以让事件触发到桌面? 这是我使用
的代码 table.setRowFactory(tv -> {
TableRow<MyObject> row = new TableRow<>();
row.setOnKeyPressed(new EventHandler<KeyEvent>() {
@Override
public void handle(KeyEvent event) {
// TODO Auto-generated method stub
System.out.println(" In the key event");
}
});
答案 0 :(得分:0)
table.setOnKeyPressed(new EventHandler<KeyEvent>() {
@Override
public void handle(KeyEvent event) {
if(event.getCode().equals(KeyCode.ENTER)) {
MyObject rowData = (MyObject)tbl.getSelectionModel().getSelectedItem();
System.out.println(rowData.getName);
}
}
});