Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javaFX event when objects are rendered

I'd like to get noticed by an event when all the objects in the Scene/Stage are displayed. This sounds like JavaFX doesn't provide this feature. Am I Right ?

I explain why:

I have to update other objects of the scene based on a TableView scroll position. Hence, I'm looking up the VirtualScrollBar of the TableView by using:

tableView.lookupAll(".scroll-bar")

which returns the desired ScrollBar only after TableView is actually rendered. Null in "initialize" block.

Architecture: I'm using a common frame - I'd say - containing an empty Pane updated runtime with actual content given the page I'd like to show. Hence I know when the content is updated, but most of the time before the TableView is rendered, which prevents me to get the ScrollBar reference.

The TableView is part of a "page" and is added to the content Pane, no update on the stage itself.

I'm using Oracle JDK8.

Do you have any clue where I can sort this out ? Thanks in advance for your help.

like image 611
Dadje Avatar asked Nov 05 '13 09:11

Dadje


1 Answers

You need to use the setOnShown() method of the Stage class to be notified when the Stage is visible. Once it is visible, all the controls have been created. The docs say as follows:

public final void setOnShown(EventHandler<WindowEvent> value)

Sets the value of the property onShown.

Property description:
Called just after the Window is shown.

like image 136
An SO User Avatar answered Sep 28 '22 03:09

An SO User