JavaFX How to determine when a Parent's layout operation is finished

123 views Asked by At

I need to perform some checks/testing only when a node's layout operation is done completely. When I am working with JavaFX 8 version, I use to rely on the needsLayout property of Parent node. This property gets updated after all the layout computing of the Parent node and its children nodes.

Below is the code of Parent's layout() in JavaFX 8:

public final void layout() {
    switch(layoutFlag) {
        case CLEAN:
            break;
        case NEEDS_LAYOUT:
            if (performingLayout) {
                break;
            }
            performingLayout = true;
            layoutChildren();
            // Intended fall-through
        case DIRTY_BRANCH:
            for (int i = 0, max = children.size(); i < max; i++) {
                final Node child = children.get(i);
                if (child instanceof Parent) {
                    ((Parent)child).layout();
                } else if (child instanceof SubScene) {
                    ((SubScene)child).layoutPass();
                }
            }
            // Flag is updated only after all the children's layout is done
            setLayoutFlag(LayoutFlags.CLEAN); 
            performingLayout = false;
            break;
    }
}

But after switching to JavaFX 18, looks like this does'nt work anymore. Because the layout flag is changed way ahead even before the Parent calls its layoutChildren.

Below is the code of Parent's layout() in JavaFX 18:

public final void layout() {
    // layoutFlag can be accessed or changed during layout processing.
    // Hence we need to cache and reset it before performing layout.
    LayoutFlags flag = layoutFlag;
    setLayoutFlag(LayoutFlags.CLEAN);
    switch(flag) {
        case CLEAN:
            break;
        case NEEDS_LAYOUT:
            if (performingLayout) {
                break;
            }
            performingLayout = true;
            layoutChildren();
            // Intended fall-through
        case DIRTY_BRANCH:
            for (int i = 0, max = children.size(); i < max; i++) {
                final Node child = children.get(i);
                currentLayoutChild = child;
                if (child instanceof Parent) {
                    ((Parent)child).layout();
                } else if (child instanceof SubScene) {
                    ((SubScene)child).layoutPass();
                }
            }
            currentLayoutChild = null;
            performingLayout = false;
            break;
    }
}

Considering the above changes in the new version., is there any way I can know if the layout of a Parent node is completed?

Note: I am aware of the Scene's postLayoutPulseListener. But that does call after the complete layoutPass. Here I am trying to look on individual Parent node level.

0

There are 0 answers