0

My task is creating the resizable graph in full screen mode. Graph must be resizable when user change the window of program that is fullscreen by default (the components and lines of graph change their sizes). I realize the graph with AnchorPane: the elements (that are GridPanes) stay in coordinates that are defined. Then I make the lines with the help of method getBoundsInParent(). Here is the scema of graph:

image

All is good but the problem is that I can t resize my graph. All components are stayed with their sizes; variables prefSize, minSize, maxSize don't do the resizing. I try using the params AnchorPane.setTopAnchor etc., but they don t resize, only move the GridPane component. Also I try to use GridPane as the layout instead the AnchorPane. But my lines that are binded with the methods component.getBoundsInParent() fly away in random positions (I understand that the getBoundsInParent() method returns other coordinates that with GridPane).

My project is located at work computers without Internet & I can t show it. I think the way of binding the lines between graphs is useful to show in code block because it is the cause of moving out the lines when the components are in GridPane layout:

line.startXProperty().bind(source.layoutXProperty().add(source.getBoundsInParent().getWidth() / 2.0));    
line.startYProperty().bind(source.layoutYProperty().add(source.getBoundsInParent().getHeight() / 2.0));
line.endXProperty().bind(target.layoutXProperty().add(target.getBoundsInParent().getWidth() / 2.0));
line.endYProperty().bind(target.layoutYProperty().add(target.getBoundsInParent().getHeight() / 2.0));

What is the way to resize the graph with elements that I create and lines that are connected with this elements. May be it s the properties of AnchorPane or GridPane? Or some binding of start & endpoints of lines?

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
MouvieM
  • 17
  • 1
  • 5
  • I strongly suspect you should not be using AnchorPane at all. It appears you are trying to manually perform the work of a layout. Can you edit your question and show us what you are trying to achieve visually? Either take a screen shot, or draw it in a simple paint program, or use ASCII art. – VGR Apr 15 '19 at 16:52
  • @VGR thanks for attention for my question. I have added the scema of my graph at the top of my question. As I wrote, by the default it is fullscreen but during runtime the user can change the screen size... – MouvieM Apr 15 '19 at 17:10
  • Please [edit] your question to include a [mcve] that shows the nodes you illustrate, and describe the desired result. Possible duplicate of [*Graph Visualisation (like yFiles) in JavaFX*](https://stackoverflow.com/q/30679025/230513). – trashgod Apr 15 '19 at 17:35

1 Answers1

0

Bindings need to be based on properties or other ObservableValue implementations, so changes to their values are properly tracked. Direct method calls like source.getBoundsInParent().getWidth() / 2.0 are only evaluated once, the moment that code creates the binding, so changes to the width are never seen.

line.startXProperty().bind(
    source.layoutXProperty().add(
        source.widthProperty().divide(2)));
line.startYProperty().bind(
    source.layoutYProperty().add(
        source.heightProperty().divide(2)));

If source and target are not Regions and thus don’t have a width property, you can use Bindings to create a dynamic binding of their bounds:

DoubleBinding width = Bindings.createDoubleBinding(
    () -> source.getLayoutBounds().getWidth(), 
    source.layoutBoundsProperty());

line.startXProperty().bind(
    source.layoutXProperty().add(
        Bindings.createDoubleBinding(width.divide(2)));

DoubleBinding height = Bindings.createDoubleBinding(
    () -> source.getLayoutBounds().getHeight(), 
    source.layoutBoundsProperty());

line.startYProperty().bind(
    source.layoutYProperty().add(
        Bindings.createDoubleBinding(height.divide(2)));
VGR
  • 40,506
  • 4
  • 48
  • 63