JavaFXPorts:这是Android设备上的javafx.scene.control.ComboBox的正确行为吗? [英] JavaFXPorts: Is this correct behavior for javafx.scene.control.ComboBox on Android device?

查看:173
本文介绍了JavaFXPorts:这是Android设备上的javafx.scene.control.ComboBox的正确行为吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ComboBox中选择项目后,此选定项目不会显示在ComboBox中 - 仅限Android设备,在桌面上即可。
比较这两个截图:

After selecting item in ComboBox, then this selected item is not displayed in ComboBox - only Android device, on desktop is it ok. Compare this two screenshots:

[在桌面上选择项目选项2时]

[On desktop when item "Option 2" is selected]

[在Android设备上选择项目选项2时]

[On Android device when item "Option 2" is selected]

我使用的是JavaFXPorts 8.60.8。

I am using JavaFXPorts 8.60.8.

推荐答案

基于此问题,并在错误报告你提到你使用的是S amsung设备,在一些三星设备中存在已知问题,其中在JavaFXPorts中完成的触摸事件处理在其他Android设备中不起作用。

Based on this question, and giving that on your bug report you mention you are using a Samsung device, there is a known issue in some Samsung devices where the touch event handling done in JavaFXPorts doesn't work as in the rest of Android devices.

虽然这是修复JavaFXPorts,您可以尝试以下解决方法:

While this is fix on JavaFXPorts, you can try the following workaround:

comboBox.setCellFactory(p -> new ListCell<String>() {

        private String item;
        {
            setOnMousePressed(e -> comboBox.getSelectionModel().select(item));
        }

        @Override
        protected void updateItem(String item, boolean empty) {
            super.updateItem(item, empty); 
            this.item = item;
            setText(item);
        }

    });

注意我使用了鼠标按下事件处理程序而不是鼠标单击事件处理程序。由于我无法重现它,在我的情况下,鼠标单击由列表选择事件消耗(因为这可以正常工作),但在您的情况下,您可以使用按下或单击的事件。

Note I've used a mouse pressed event handler instead of a mouse clicked event handler. Since I can't reproduce it, in my case the mouse click is consumed by the list selection event (as this works properly), but probably in your case you can use either pressed or clicked events.

这篇关于JavaFXPorts:这是Android设备上的javafx.scene.control.ComboBox的正确行为吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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