2
2つのコンポーネント:Label
& Button
があります。私はそれらを並べて、&を一緒にCENTREに整列させたいと思っています。しかし、私はそうしていませんでした。彼らはまだLEFTではなくCENTERとは一線を画しています。JavaFX複数のコンポーネントを並べる方法
次のように私のコード:
Label sloganLbl = new Label("With cost as low as $1.99, you can own a fraction share of U.S. stock. No account yet?");
sloganLbl.getStyleClass().add("blue-small-font");
Button signUpBtn = new Button("Open account now");
signUpBtn.getStyleClass().add("green-btn-small-font");
GridPane topGrid = new GridPane();
topGrid.setHgap(20);
topGrid.add(sloganLbl, 0, 0);
topGrid.add(signUpBtn, 1, 0);
topGrid.setGridLinesVisible(true);
GridPane.setHalignment(sloganLbl, HPos.RIGHT);
GridPane.setHalignment(signUpBtn, HPos.LEFT);
BorderPane topBorder = new BorderPane();
topBorder.setPadding(new Insets(15, 10, 15, 10));
topBorder.setCenter(topGrid);
topBorder.getStyleClass().add("blue-small-font");
topGrid.getStyleClass().add("blue-small-font");
borderPane.setTop(topBorder);
問題がtopBorder.setCenter(topGrid);
では、中心にあるコンテンツをセンタリングすることができません。 topGrid
は2列の合計幅だけでなく、全幅を占めているようです。
どのようにセンターアライメントを達成できますか?ありがとう!
非常に涼しい@DVarga、あなたのコードは私の問題を解決しました。本当にありがとう! –