【问题标题】:Compare setOnAction event with Keycode将 setOnAction 事件与 Keycode 进行比较
【发布时间】:2017-11-21 09:39:58
【问题描述】:

有没有办法将 setOnAction 事件与 Keycode(如向上和向下箭头)进行比较?

这是我的示例:

 comboBox.setOnAction(e ->{
//compare event key with KeyCode up or down
                if(e.getSource().equals(KeyCode.DOWN)) {
                    // do stuff
                } else {
                comboBox.hide();
                // do some other stuff
                }
            });

【问题讨论】:

  • “将 setOnAction 事件与 Keycode 进行比较”是什么意思?这没有意义。你能解释一下你真正想要做什么吗?

标签: javafx listener actionlistener keycode


【解决方案1】:

试试这个

comboBox.setOnKeyPressed(ke->{
    if(ke.getCode().equals(KeyCode.DOWN)){
        // do stuff
    }
    else{
        comboBox.hide();
        // do some other stuff
    }
})

【讨论】:

    猜你喜欢
    • 2019-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多