Threading and Node.lookup

Scott Palmer swpalmer at gmail.com
Tue Mar 19 17:24:05 PDT 2013


I always guess that wrong :-(

I just remembered that something was non-intuitive about it.  But I got it backwards this time (again).  I always code it *without* the # and then have to scratch my head for a while trying to figure it out. Precisely because the node name does *not* have the # and # is a CSS/XML syntax thing and I'm coding Java not CSS!

Oh well,

Scott

On 2013-03-19, at 7:58 PM, Philipp Dörfler <phdoerfler at gmail.com> wrote:

> And that's what lookup and ID is for, according to Node.idProperty's javadoc:
> 
>> For example, if a Node is given the id of "myId", then the lookup method can be used to find this node as follows: scene.lookup("#myId");.
> 
> http://docs.oracle.com/javafx/2/api/javafx/scene/Node.html#idProperty()
> 
> ~ philipp
> 
> Am 20.03.2013 um 00:53 schrieb Scott Palmer <swpalmer at gmail.com>:
> 
>> My guess is drop the "#".  That's a CSS thing and not part of the ID.
>> 
>> 
>> Scott
>> 
>> On 2013-03-19, at 7:50 PM, Kevin Rushforth <kevin.rushforth at oracle.com> wrote:
>> 
>>> One of the scene graph or FXML folks should be able to reply.
>>> 
>>> -- Kevin
>>> 
>>> 
>>> Philipp Dörfler wrote:
>>>> Ok, threading aside: Where's my mistake?
>>>> 
>>>> https://gist.github.com/phdoerfler/5201162
>>>> 
>>>> ~ philipp
>>>> 
>>>> Am 20.03.2013 um 00:30 schrieb Kevin Rushforth <kevin.rushforth at oracle.com>:
>>>> 
>>>> 
>>>>>> As to my understanding, one only has to use Platform.runLater for accessing nodes already attached to a Scene.
>>>>>> 
>>>>> In general is is legal to call accessor and mutator methods on a Node not attached to a Scene from any thread. I don't specifically know whether lookup does anything that would add additional threading restrictions.
>>>>> 
>>>>> -- Kevin
>>>>> 
>>>>> 
>>>>> Philipp Dörfler wrote:
>>>>> 
>>>>>> Hi,
>>>>>> 
>>>>>> does fooNode.lookup("#bar") have to be called using Platform.runLater if fooNode is not attached to any Scene?
>>>>>> As to my understanding, one only has to use Platform.runLater for accessing nodes already attached to a Scene.
>>>>>> 
>>>>>> However, fooNode.lookup seems to fail (= return null) for nodes which are not contained directly in it, but in another node (in my case: a ScrollPane), which is then contained in fooNode. The scene graph was provided by FXMLLoader.load(...).
>>>>>> 
>>>>>> Placing those lookups in Platform.runLater suddenly causes them to work.
>>>>>> 
>>>>>> This feels like an arcane bug to me, but I might be missing some core concepts.
>>>>>> So - did I miss something or is this a bug?
>>>>>> 
>>>>>> Cheers,
>>>>>> Philipp
>>>>>> 
>>>> 
>>>> 
>> 
> 



More information about the openjfx-dev mailing list