2017-10-04 83 views
-1

我试图调整一些窗格的大小,如果一个元素有LayoutX < 0. 我已经创建了一个存储偏移量来调整大小的DoubeProperty。节点没有调整大小

监听器是这样的:

offset.addListener((observable, oldValue, newValue) -> { 
    if(newValue.doubleValue() > 0) { 
     setPrefWidth(getWidth() + newValue.doubleValue());  
    } 
}); 

但TE节点没有; T改变他的财产。当我点击元素时,我看到偏移量比0更多。我如何强制调整大小?

我也想用绑定:

prefWidthProperty().bind(Bindings.when(Bindings.isNotEmpty(children)) 
      .then(Bindings.when(offset.greaterThan(0)) 
        .then(widthProperty().add(offset)) 
        .otherwise(widthProperty())) 
      .otherwise(MINIMAL_RELATION_WIDTH) 
      ); 

但相同的结果。奇怪的是,如果我添加一个事件悬停到其他元素(例如阴影),改变BoundsInLocalProperty ..我看到,调整大小执行afet悬停在元素上。我不明白为什么

回答

0

我准解决我的问题......

我有4个窗格扩展BorderPane:

  • ChildPane
  • RelationExPane
  • SinglePane
  • RelationCurentPane

ChildPane包含3个其他人。而RelationExPane,SinglePane,RelationCurrentsPane在Hbox中包含一些ChildPanes。

在RelationExPane和SinglePane中,我拥有2个元素,第一个LayoutX依赖于其他的LayoutX。有时候应该是LayoutX将为< 0.在这种情况下,我实现了将调整Node大小的侦听器或LayoutX,但它没有按照我在帖子中提到的那样工作。结果是这样的:

enter image description here

这是国家刚刚生成树之后。在(+)元素上,我添加了只添加阴影的onEnter事件。当我在那里移动鼠标时,元素被正确放置。我不明白为什么(我知道这下进行更改在此元素的父约束,但通常它不应该影响其他窗格。

我被Ovveride computePrefWith功能我的问题的一种解决方法

对于关系EX:

@Override 
protected double computeMinWidth(double height) { 
    Double offset = 0.0; 
    if(spouseCard.getLayoutX() < 0) { 
     offset = (spouseCard.getLayoutX()*(-1)) +20; 
    } 

    return super.computeMinWidth(height)+ offset; 
} 

而对于关系当前

@Override 
    protected double computePrefWidth(double height) { 
     Double offset = 0.0; 
     Double maxRelationWidth = spouseCard.getLayoutX() + spouseCard.getWidth(); 
     if(maxRelationWidth > relation.getWidth()) { 
      offset = maxRelationWidth+10; 
     } 
     return super.computePrefWidth(height)+offset; 
    } 

现在第一落点我好的。但是当我移动(+)元素时,我仍然有问题。在这种情况下,每个moveOn或moveOut将节点的大小调整为不同大小。