ComboBox SAME 项目选定动作侦听器 [英] ComboBox SAME item selected action listener

查看:39
本文介绍了ComboBox SAME 项目选定动作侦听器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果选择了不同的值,组合框将触发一个事件.我还希望能够收听被选中的 SAME 项目(即 valueProperty 没有变化).似乎没有办法做到这一点.

A combo box will fire an event if a DIFFERENT value is selected. I want to be also be able to listen to the SAME item being selected (that is, valueProperty has no change). There seems to be no way to do this.

我尝试扩展 ComboBox 并找到一种方法来监听关闭的小弹出菜单,但我什至无法访问它!我能做什么?

I tried extending the ComboBox and finding a way to listen for the little popup menu being closed, but I don't even have access to that! What can I do?

这是我正在尝试的:

class ResponsiveComboBox<E> extends ComboBox<E> {

    public ResponsiveComboBox() {
        super();
        assert getContextMenu() != null; //Asssertion failed!
        this.getContextMenu().setOnHiding((WindowEvent event) -> {
            fireEvent(new ActionEvent());
        });
    }

}

推荐答案

comboBox.showingProperty().addListener((obs, wasShowing, isShowing) -> {
    if (! isShowing) {
        System.out.println("Combo box popup hidden");
    }
});

此事件处理程序可能会在更改值之前触发.

This event handler might be triggered before the value is changed.

这篇关于ComboBox SAME 项目选定动作侦听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆