VBoxを操作しようとしていますが、これには最大5つのボタンを含むHBoxを最大5つ設定します。 また、これらのボタンのサイズを変更する必要がありますが、完了することができません。 はすでにボタンでシーン全体を塗りつぶします。
primaryStage.getChildren.addAll(hBoxMethod());
ヘルプは非常に高く評価されるだろう:)あなたがやろう何
VBoxを操作しようとしていますが、これには最大5つのボタンを含むHBoxを最大5つ設定します。 また、これらのボタンのサイズを変更する必要がありますが、完了することができません。 はすでにボタンでシーン全体を塗りつぶします。
primaryStage.getChildren.addAll(hBoxMethod());
ヘルプは非常に高く評価されるだろう:)あなたがやろう何
正確にわからないから、それを呼び出し、HBoxのを返す静的メソッドを使用しようとしました。しかし、5x5自動サイズ変更ボタン(タイトルのsujectsとして)であなたのsceenを埋めることを試みているなら、なぜサイズ変更にGridPaneとAnchorPanesの組み合わせを使用しないのですか?
package sample;
import javafx.application.Application;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.*;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
AnchorPane rootPane = new AnchorPane();
Scene scene = new Scene(rootPane, 400, 300);
GridPane grid = new GridPane();
MaximizeInAnchorPane(grid);
// make column and rows resize
for (int i=0;i <5;i++)
{
ColumnConstraints cConstrain = new ColumnConstraints();
cConstrain.setHgrow(Priority.SOMETIMES);
grid.getColumnConstraints().add(cConstrain);
RowConstraints rConstrain = new RowConstraints();
rConstrain.setVgrow(Priority.SOMETIMES);
grid.getRowConstraints().add(rConstrain);
}
for (int i=0;i <5;i++)
{
for (int j=0;j <5;j++)
{
// create button and put it in an AnchorPane, that will resize it
AnchorPane buttonPane = new AnchorPane();
Button button = new Button("Button");
MaximizeInAnchorPane(button);
buttonPane.getChildren().add(button);
grid.add(buttonPane,i,j);
}
}
rootPane.getChildren().add(grid);
primaryStage.setTitle("test");
primaryStage.setScene(scene);
primaryStage.show();
}
private static void MaximizeInAnchorPane(Node toMaximize)
{
AnchorPane.setTopAnchor(toMaximize, 0.0);
AnchorPane.setRightAnchor(toMaximize, 0.0);
AnchorPane.setLeftAnchor(toMaximize, 0.0);
AnchorPane.setBottomAnchor(toMaximize, 0.0);
}
public static void main(String[] args) {
launch(args);
}
}
手動ですべてのサイズを変更しようとしている場合は、SplitPaneを見てください。それはどのようにサイズを変更するかによって異なります。
私にとっては、JavaFXシーンビルダJavaFX Scene Builderを使って、私が望むレイアウトをどうやってやっていくのかが常にわかります。
各ボタンは、店舗が提供する、データベースにある商品を分類して表示しています。 たとえば、セールスマンがソーダを売却することを選択した場合、コークス、スプライトなどの店舗にあるソーダがすべて画面に表示されます。 常に商品が25個あるとは限りませんが、 25以上の場合には限界がありますが、それほどよく分類されていない限り、それほど有望ではありません。 あなたの答えをありがとう、私は入れ子を操作しようとするので、私は望んでいるボタンの数だけを追加します。 –
お試しいただいた内容をお見せください – Mostafiz