Hej,

Mam Border Pane i chce aby topPane i BottomPane byly zawsze na górze, jako ostatnie indexy. Mam pewna klase BorderPaneReloadHelper, ale ona działa w ten sposob ze najpier robi getChildren().clear() a potem dopiero ponownie dodaje.

Jako ze chce ustawic listener na parentProperty() to, to nieco mnie impaktuje. Ma ktos jakis pomysł ?


Próbje sama jakis comparator napisac ale cos mi to nie idzie :


    private List<Node> permutation;
    private Comparator<Node> comparator;

    public void permutate(BorderPane pane) {
        initComparator(pane);
        pane.getChildren().sort(comparator);
    }

    private void initComparator(BorderPane pane) {
        List<Node> permutation = new ArrayList<>();
       for( Node n : Arrays.asList(pane.getRight(), pane.getLeft(), pane.getCenter(), pane.getTop(), pane.getBottom())){
           if (n != null) permutation.add(n);
       }

        comparator = (o1, o2) -> {
            int o1P = permutation.indexOf(o1);
            int o2P = permutation.indexOf(o2);
            System.out.println("Node o1 is : " +o1 + "his id i permuation is " +o1P);
            System.out.println("Node o2 is : " +o2 + "his id i permuation is " +o2P);
            return o1P - o2P;
        };
    }

Dostaje exception :


java.lang.IllegalArgumentException: Children: duplicate children added: parent = BorderPane[id=rootBorderPane]
	at javafx.scene.Parent$2.onProposedChange(Parent.java:454)
	at com.sun.javafx.collections.VetoableListDecorator$VetoableListIteratorDecorator.set(VetoableListDecorator.java:768)
	at java.util.List.sort(List.java:482)
	at gentree.client.desktop.configuration.helper.BorderPanePermutateHelper.permutate(BorderPanePermutateHelper.java:25)
	at gentree.client.desktop.service.ScreenManager.loadFxml(ScreenManager.java:171)
	at gentree.client.desktop.service.ScreenManager.init(ScreenManager.java:116)
	at gentree.client.desktop.GenTreeRun.start(GenTreeRun.java:27)
	at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
	at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
	at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
	at java.security.AccessController.doPrivileged(Native Method)
	at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
	at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)