2016-12-04 5 views
0

異なるサイズのマップをペイン上に描画しています。あるものはうまく見え、他のものはちょうど小さな形として提示され、正しいサイズにするためにはズームインする必要があります。私はそれらのマップを私が初期化するたびにおおよそ同じサイズで表示したい(私は手動で各マップを拡大する必要はありません)。私は、minPoint2Dポイントと、xの値とyの値を描画しているので、マップ(同じポリゴンのGroup)になります。たとえばminPointPaneの間の距離をminPointからGroupに設定するにはどうすればよいですか?または私はこれに間違った方法で近づいていますか?JavaFX異なるサイズのノードを同じサイズにスケーリングする

編集:私もその1本のラインがわからない、それを行う上で、計画方法です

public void setDistance(Group map, Point2D paneSize, Point2D mapSize){ 
    //um diese distance verschieben, if distance > 10px (scale) 
    double d = paneSize.distance(mapSize); 
    double scale = ?? 
    map.setScaleX(scale); 
    map.setScaleY(scale); 
} 

答えて

0

ノードを親ノードのサイズに合わせるには、サイズの違いは重要ではありません。重要なことは、サイズの商、より正確には高さと幅の商の最小値です(親を一方向に完全に埋めると仮定した場合)。

例:

@Override 
public void start(Stage primaryStage) { 
    Text text = new Text("Hello World!"); 

    Pane root = new Pane(); 
    root.getChildren().add(text); 
    InvalidationListener listener = o -> { 
     Bounds rootBounds = root.getLayoutBounds(); 
     Bounds elementBounds = text.getLayoutBounds(); 

     double scale = Math.min(rootBounds.getWidth()/elementBounds.getWidth(), 
       rootBounds.getHeight()/elementBounds.getHeight()); 
     text.setScaleX(scale); 
     text.setScaleY(scale); 

     // center the element 
     elementBounds = text.getBoundsInParent(); 
     double cx = (elementBounds.getMinX() + elementBounds.getMaxX())/2; 
     double cy = (elementBounds.getMinY() + elementBounds.getMaxY())/2; 
     text.setTranslateX(rootBounds.getWidth()/2 - cx + text.getTranslateX()); 
     text.setTranslateY(rootBounds.getHeight()/2 - cy + text.getTranslateY()); 
    }; 

    root.layoutBoundsProperty().addListener(listener); 
    text.layoutBoundsProperty().addListener(listener); 

    Scene scene = new Scene(root); 

    primaryStage.setScene(scene); 
    primaryStage.show(); 
} 
+0

が働くこと、ありがとうございました! – dot

関連する問題