我想将焦点放在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();更多推荐
发布评论