将焦点设置在ControlsFX中的PropertySheet项目节点上(Set focus on PropertySheet Item Node in ControlsFX)

编程入门 行业动态 更新时间:2024-10-24 19:15:49
将焦点设置在ControlsFX中的PropertySheet项目节点上(Set focus on PropertySheet Item Node in ControlsFX)

我想将焦点放在ControlsFX中的PropertySheet.Item Node(例如TextField )上。 PropertySheet Item具有唯一的名称,因此我可以找到PropertySheet.Item ,其代码为propertySheet.getItems().get(i).getName() 。 但是没有API来获取与属性项对应的Node 。 我看到的唯一解决方案是使用getChildrenUnmodifiable方法遍历场景图 。 但是,当我使用此方法遍历PropertySheet ,它返回:

PropertySheet@1ab0e7e0[styleClass=property-sheet] BorderPane@46e1b462 ToolBar@93ba99a[styleClass=tool-bar] SegmentedButton@d5c968[styleClass=segmented-button] HBox@1c3283db ToggleButton@2fffaccc[styleClass=toggle-button left-pill]''

我没有得到任何Propertysheet节点,如TextField或ComboBox 。 有可能吗? 谢谢。

I want to set focus on PropertySheet.Item Node (for example TextField) in ControlsFX. PropertySheet Item have unique name, so i can find PropertySheet.Item with code propertySheet.getItems().get(i).getName(). But there is no API to get Node which corresponds to property item. The only solution i see is to walk scene graph with method getChildrenUnmodifiable. But when i traverse PropertySheet with this method it returns:

PropertySheet@1ab0e7e0[styleClass=property-sheet] BorderPane@46e1b462 ToolBar@93ba99a[styleClass=tool-bar] SegmentedButton@d5c968[styleClass=segmented-button] HBox@1c3283db ToggleButton@2fffaccc[styleClass=toggle-button left-pill]''

I don't get any Propertysheet Nodes such as TextField or ComboBox. Is it possible to do it? Thank you.

最满意答案

我找到了解决方案。 您必须使用setPropertyEditorFactory和全局hashmap变量来存储所有节点,以便稍后访问它。 示例代码如下。

public Map<String, Node> nodes = new HashMap<>(); SimpleObjectProperty<Callback<PropertySheet.Item, PropertyEditor<?>>> propertyEditorFactory = new SimpleObjectProperty<>(this, "propertyEditor", new DefaultPropertyEditorFactory()); propertySheet.setPropertyEditorFactory((PropertySheet.Item param) -> { PropertyEditor node = propertyEditorFactory.get().call(param); nodes.put(uniquePropertyName, node.getEditor()); return node; });

在此之后,您可以将属性Node聚焦于:

nodes.get(propertyName).requestFocus();

I found a solution. You must use setPropertyEditorFactory and global hashmap variable which will store all Nodes, so you can access it later. Sample code below.

public Map<String, Node> nodes = new HashMap<>(); SimpleObjectProperty<Callback<PropertySheet.Item, PropertyEditor<?>>> propertyEditorFactory = new SimpleObjectProperty<>(this, "propertyEditor", new DefaultPropertyEditorFactory()); propertySheet.setPropertyEditorFactory((PropertySheet.Item param) -> { PropertyEditor node = propertyEditorFactory.get().call(param); nodes.put(uniquePropertyName, node.getEditor()); return node; });

After this you can focus property Node with:

nodes.get(propertyName).requestFocus();

更多推荐

本文发布于:2023-08-03 14:31:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1390594.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:节点   焦点   项目   PropertySheet   ControlsFX

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!