JavaFXの中layoutBoundsにおけるスケールファクタを含みます

Chaoskatze:

私はJavaFXの8を使用しています。

のJavaDocをからjavafx.scene.Node.scaleYProperty()

[...]このスケールファクタは、すべてのエフェクトや変換が考慮された後、ノード全体をスケーリングのために最適ですこれは、デフォルトでlayoutBoundsには含まれていません。[...]

どのようにすることができます私はかかわらず、layoutBoundsにスケーリング係数が含まれていますか?

いくつかのコンテキスト:ボタンを押すと次の例では、私はGridPaneがRowConstraintsのprefHeightをハードコーディングすることwhithoutのHBoxのスケーリングにも反応するようにしたいと思います。

layoutBoundsに倍率を含めることができることは、おそらくトリックを行うだろうが、他の解決策はあるとしても歓迎します。

import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.ToggleButton;
import javafx.scene.layout.*;
import javafx.stage.Stage;

public class ScalingStandAlone extends Application {

    private VBox vBox = new VBox();
    private GridPane gridPane = new GridPane();
    private HBox  hBox = new HBox();
    private ToggleButton button = new ToggleButton("Click to scale");
    private Label firstRowLabel = new Label("Some content in text form");
    private Label secondRowLabel = new Label("Some content for scaling");
    private Label thirdRowLabel = new Label("Some moving content");

    public static void main(String[] args) {
        Application.launch(args);
    }

    @Override
    public void start(Stage stage) throws Exception {
        AnchorPane root = new AnchorPane();
        AnchorPane.setTopAnchor(vBox, 5.);
        AnchorPane.setLeftAnchor(vBox, 5.);
        AnchorPane.setRightAnchor(vBox, 5.);
        root.autosize();
        Scene scene = new Scene(root);
        stage.setTitle("GridRow Scale Demo");
        stage.setWidth(400);
        stage.setHeight(300);
        stage.setScene(scene);
        stage.show();

        root.getChildren().add(vBox);
        vBox.setAlignment(Pos.CENTER);
        vBox.getChildren().add(gridPane);
        vBox.getChildren().add(button);
        vBox.setStyle("-fx-spacing: 15;");

        configureGridPane(root);

        button.setOnAction(event -> {
            hBox.setScaleY(button.isSelected() ? 2 : 1);
        });
    }

    private void configureGridPane(Pane root) {
        hBox.getChildren().add(secondRowLabel);

        // Styling //
        firstRowLabel.setStyle("-fx-padding: 5;");
        hBox.setStyle("-fx-background-color: #800000; -fx-padding: 5;");
        secondRowLabel.setStyle("-fx-text-fill: white; -fx-padding: 5;");
        thirdRowLabel.setStyle("-fx-padding: 5;");

        gridPane.add(firstRowLabel, 0, 0);
        gridPane.add(hBox, 0, 1);
        gridPane.add(thirdRowLabel, 0, 2);
        gridPane.setGridLinesVisible(true);
        gridPane.getColumnConstraints().add(new ColumnConstraints());
        gridPane.getColumnConstraints().get(0).setPercentWidth(100);
    }
}
James_D:

以下からのJavadocGroup

どれでも、効果を変換、または状態がグループに適用され、そのグループのすべての子に適用されます。このような変換及び効果は、このグループのレイアウト境界には含まれません変換および効果は、このグループの子どもたちに直接設定されている場合しかし、それらは、このグループのレイアウト境界に含まれます

(私の強調は追加しました)。

あなたは、単にあなたを包む場合したがって、HBoxGroup、あなたは所望の効果を達成します。

    // gridPane.add(hBox, 0, 1);
    gridPane.add(new Group(hBox), 0, 1);

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=318537&siteId=1