Friday, September 1, 2017

How to automaticly resize anchor pane if element change LayoutX

Leave a Comment

I have a problem when I set layoutX to child element in AnchorPane. This element exceed border of ParentAnchor Pane ? there is other way that set listener on each child's width property ?

Code Example of usage:

relation.heightProperty().addListener((observable, oldValue, newValue) -> {     if (relationTypeElement != null) {         relationTypeElement.setTranslateY((newValue.doubleValue() - relationTypeElement.getHeight() - MARGIN_BOTTOM - PADDING_TOP) / 2);     } });  relationTypeElement.heightProperty().addListener((observable, oldValue, newValue) -> {     relationTypeElement.setTranslateY((relation.getHeight() - newValue.doubleValue() - MARGIN_BOTTOM - PADDING_TOP) / 2); });   childrenBox.widthProperty().addListener(observable -> {     relationTypeElement.setTranslateX(childrenBox.getWidth()/2);     spouseCard.setTranslateX(relationTypeElement.getTranslateX() + 200); }); 

@Edit...
Another thing bizzare... when I use code like this :

Double dd = relationTypeElement.getLayoutX +200; spouseCard.setLayoutX(dd); 

The element exceed border of his parent Pane.

But when I use :

spouseCard.setLayoutX(1400); 

The element is placed correctly, and parent Pane is resizing.


After many tries, I was tasting this code:

private void calculateRelationElementsPosition() {     if (children.size() > 0) {         Line line = childrenConnector.getLine();         Double offset = line.getEndX() + relationTypeElement.getWidth()/2 -5;         AnchorPane.setRightAnchor(relationTypeElement, offset);         AnchorPane.setRightAnchor(spouseCard, offset + 200);         childrenConnector.connectRelationToChildren(relationTypeElement);     } else {        // relationTypeElement.setLayoutX(100);     } } 

But the result is still not stysfying.

@Edit for @fabian This project is a kind of genealogy tree.. but more precise is a graph/map of relations structure in the Sims. After profond research any other programm doesnt show in ONE picture all relations (also with ex-spouse and their asc/desc).

So.. this map is divided by Module class. In one mode I draw the tree for one familly starting by root. So this is the main parent.

class: ChildPanel extend BorderPane { Left: Hbox panelRelationEx Center: AnchorPane panelSingle Right: AnchorPane panelRelationCurrent } 

In Hbox I put:

   class : PanelRelationEx extends BorderPane {     Top: AnchorPane relation (contain graphical representation of spouse and relationtype)     Center: Hbox children ( containnign objects of class ChildPanel)     }      class: PanelRelationCurrent extends BorderPane {     Top: AnchorPane relation (contain graphical representation of spouse and relationtype)     Center: Hbox children ( containnign objects of class ChildPanel)     } 

PanelEx and PanelCurrent are similar. The difference is in allignment items.

When I add children do Hbox I draw line connecting them, and at next I deplace elements in AnchorPane relation. To first, last child or on center of connecting line.

Function for deplace objects work fine. LayoutX and Y property are correctly set. But I have a problem with sizing Pane. For example. When I add new element to Hbox ( children) the Hbox grow that cause growing of his parent and all tree. When I set LayoutX for elements in AnchorPane relation and there is only 1 child in Hbox. The elements are out of the bord of AnchorPane relation

enter image description here

When I use function

relation.resize(newWidth, newHeight)  

In my trigger, the Anchor Pane relation is resized, but this time, it is out of the bord of HisParent (BorderPane.getTop)

the case of RelationEx is a little bit more complicated, because the LayoutX of spouse card is negative.

0 Answers

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment