How does getProperties() method work?
Greg Brown
greg.x.brown at oracle.com
Fri Jun 22 08:43:15 PDT 2012
com.sun.javafx.fxml.BeanAdapter can also be used for this. It exposes an object's bean properties via the Map interface.
On Jun 22, 2012, at 9:59 AM, Jeff Martin wrote:
> Something like this should work:
>
> /**
> * Returns properties for JavaFX object.
> */
> public List <Property> getProperties(Object anObj)
> {
> // Create list and get class methods
> List <Property> properties = new ArrayList();
> Method methods[] = anObj.getClass().getMethods();
>
> // Iterate over methods, if method returns property, get it
> for(Method method : methods) {
> if(Property.class.isAssignableFrom(method.getReturnType()))
> try { properties.add((Property)method.invoke(anObj, new Object[0])); }
> catch(Exception e) { System.err.println("Error: " + e); continue; }
> }
>
> // Return properties
> return properties;
> }
>
> jeff
>
>
> On Jun 22, 2012, at 7:08 AM, goddard at seznam.cz wrote:
>
>> I see.
>> Is there a way how to query a Node for its set of JavaFX properties then?
>>
>> Thanks, Jiri
>>
>> ------------ Původní zpráva ------------
>> Od: Eva Krejcirova <eva.krejcirova at oracle.com>
>> Předmět: Re: How does getProperties() method work?
>> Datum: 22.6.2012 14:02:42
>> ----------------------------------------
>> Hi,
>>
>> Node.getProperties returns an ObservableMap which you then can use to
>> store any information you want. It is similar to
>> getUserData/setUserData which actually store the user data in the same map.
>> It has nothing to do with JavaFX properties of a node.
>>
>> We should probably improve the documentation of this method, the current
>> javadoc doesn't seem to clarify this.
>>
>> Eva
>>
>> On 6/22/2012 1:14 PM, goddard at seznam.cz wrote:
>>> Hi,
>>>
>>> I wanted to query a Rectangle for its properties with getProperties() method,
>> but it always returns empty Map (no elements, zero size).
>>> For example, I've got a Rectangle defined like this:
>>>
>>> Rectangle red = RectangleBuilder.create()
>>> .x(100).y(100)
>>> .width(100).height(100)
>>> .fill(Color.RED)
>>>
>> //.stroke(Color.BLACK).strokeWidth(3).strokeType(StrokeType.OUTSIDE)
>>> .rotate(45)
>>> .build();
>>>
>>> Regards, Jiri
>>
>>
>>
>
More information about the openjfx-dev
mailing list