print JavaFX Node Tree - Java JavaFX

Java examples for JavaFX:Node

Description

print JavaFX Node Tree

Demo Code


import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Point2D;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Control;
import javafx.scene.control.Label;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBoxBuilder;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.Window;

public class Main{
    public static void printNodeTree(Node n) {
        StringBuilder sb = new StringBuilder();
        printNodeTree(sb, 0, n);//from  www.j  av a  2s .  c o  m
        System.out.println(sb.toString());
    }
    protected static void printNodeTree(StringBuilder sb, int level, Node n) {
        if (level > 0) {
            sb.append('\n');
        }
        sb.append(StringUtil.getRepeatedString("  ", level)).append(
                n == null ? "null" : n.toString());
        if (n != null && n instanceof Parent) {
            Parent p = (Parent) n;
            for (Node nn : p.getChildrenUnmodifiable()) {
                printNodeTree(sb, level + 1, nn);
            }
        }
    }
}

Related Tutorials