VBox
で作業しているImに3つのラベルを追加しました。ラベル間の垂直方向の間隔は、setSpacing()
の方法で設定します。しかし、それは固定値です、例えば20
です。値を50
に変更すると、スペースが増えます。しかし、それはハードコーディングです。JavaFX VBoxの要素を均等に配布する方法
(VBox
の高さに基づいて)ラベルが均等に配分されるように私が使用できる事前定義された方法があるかどうかを知りたいと思います。ウィンドウのサイズを変更した場合、ラベル(つまり、ラベル間のスペース)は、(2つのラベルの間に同じスペースで)均等に分散されるように調整する必要があります。 "5表示行" で
VBox
がBorderPane
の左側に設定されているように、私は "lab0" 欲しい時 "表示行1"、 "LAB1" と「LAB2 「ディスプレイライン9」(整列の点で)である。 TextFields
を追加する場合は、「lab2」が最後に「ディスプレイラインX」になるはずです。
私のコードはここに...マークしてください。あなたは何ができるか
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextField;
import javafx.scene.control.ToggleGroup;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.text.Font;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
public class MyJavaFx extends Application
{
public MyJavaFx()
{
}
public void start(Stage primaryStage)
{
BorderPane pane = new BorderPane();
pane.setTop(getRadioButtons());
pane.setBottom(getPushButtons());
pane.setLeft(getLeftLabels());
pane.setRight(getRightLabels());
pane.setCenter(getTextFields());
Scene scene=new Scene(pane,1000,800);
primaryStage.setTitle("Even");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String arg[])
{
Application.launch(arg);
}
FlowPane getRadioButtons()
{
FlowPane pane = new FlowPane();
pane.setPadding(new Insets(10,10,10,10));
pane.setHgap(10);
RadioButton rb[]=new RadioButton[3];
ToggleGroup radioGroup = new ToggleGroup();
for(int i=0;i<rb.length;i++)
{
rb[i] = new RadioButton("Flag "+(i+1));
rb[i].setToggleGroup(radioGroup);
pane.getChildren().add(rb[i]);
}
rb[0].setSelected(true);
pane.setAlignment(Pos.CENTER);
return pane;
}
FlowPane getPushButtons()
{
FlowPane pane = new FlowPane();
pane.setPadding(new Insets(10,30,30,10));
pane.setHgap(10);
Button rb[]=new Button[3];
for(int i=0;i<rb.length;i++)
{
rb[i] = new Button("but"+i);
pane.getChildren().add(rb[i]);
}
pane.setAlignment(Pos.BOTTOM_RIGHT);
return pane;
}
VBox getLeftLabels()
{
VBox pane = new VBox();
pane.setPadding(new Insets(10,10,10,10));
pane.setSpacing(20);
Label ll[]=new Label[3];
for(int i=0;i<ll.length;i++)
{
ll[i] = new Label("lab"+i);
pane.getChildren().add(ll[i]);
}
ll[0].setAlignment(Pos.TOP_LEFT);
ll[1].setAlignment(Pos.CENTER_LEFT);
ll[2].setAlignment(Pos.BOTTOM_LEFT);
pane.setAlignment(Pos.CENTER_LEFT);
return pane;
}
VBox getRightLabels()
{
VBox pane = new VBox();
pane.setPadding(new Insets(10,10,10,10));
pane.setSpacing(20);
Label rb[]=new Label[3];
for(int i=0;i<rb.length;i++)
{
rb[i] = new Label("lab"+i);
pane.getChildren().add(rb[i]);
}
pane.setAlignment(Pos.CENTER_RIGHT);
return pane;
}
VBox getTextFields()
{
VBox pane = new VBox();
pane.setPadding(new Insets(10,10,10,10));
pane.setSpacing(2);
TextField tf[]=new TextField[9];
for(int i=0;i<tf.length;i++)
{
tf[i] = new TextField("Display Line "+(i+1));
pane.getChildren().add(tf[i]);
}
pane.setAlignment(Pos.CENTER_RIGHT);
return pane;
}
}