Javafx-layout-borderpane
提供:Dev Guides
JavaFX-レイアウトBorderPane
BorderPaneを使用する場合、ノードは上、左、右、下、中央の位置に配置されます。
パッケージ javafx.scene.layout の BorderPane というクラスは、BorderPaneを表します。
このクラスには、次の5つのプロパティが含まれます-
- bottom -このプロパティは Node タイプであり、BorderPaneの下部に配置されたノードを表します。 セッターメソッド* setBottom()*を使用して、このプロパティに値を設定できます。
- center -このプロパティは Node タイプであり、BorderPaneの中央に配置されたノードを表します。 セッターメソッド* setCenter()*を使用して、このプロパティに値を設定できます。
- left -このプロパティは Node タイプであり、BorderPaneの左側に配置されたノードを表します。 セッターメソッド* setLeft()*を使用して、このプロパティに値を設定できます。
- right -このプロパティは Node タイプであり、BorderPaneの右側に配置されたノードを表します。 セッターメソッド* setRight()*を使用して、このプロパティに値を設定できます。
- top -このプロパティは Node タイプであり、BorderPaneの上部に配置されたノードを表します。 セッターメソッド* setTop()*を使用して、このプロパティに値を設定できます。
これらに加えて、このクラスは次のメソッドも提供します-
- * setAlignment()*-このメソッドは、このペインに属するノードの配置を設定するために使用されます。 このメソッドは、ノードと優先度の値を受け入れます。
例
次のプログラムは、 BorderPane レイアウトの例です。 ここでは、上、下、右、左、中央の位置に5つのテキストフィールドを挿入しています。
このコードを BorderPaneExample.java という名前のファイルに保存します。
import javafx.application.Application;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public class BorderPaneExample extends Application {
@Override
public void start(Stage stage) {
//Instantiating the BorderPane class
BorderPane bPane = new BorderPane();
//Setting the top, bottom, center, right and left nodes to the pane
bPane.setTop(new TextField("Top"));
bPane.setBottom(new TextField("Bottom"));
bPane.setLeft(new TextField("Left"));
bPane.setRight(new TextField("Right"));
bPane.setCenter(new TextField("Center"));
//Creating a scene object
Scene scene = new Scene(bPane);
//Setting title to the Stage
stage.setTitle("BorderPane Example");
//Adding scene to the stage
stage.setScene(scene);
//Displaying the contents of the stage
stage.show();
}
public static void main(String args[]){
launch(args);
}
}
次のコマンドを使用して、コマンドプロンプトから保存したJavaファイルをコンパイルして実行します。
javac BorderPaneExample.java
java BorderPaneExample
実行時に、上記のプログラムは以下に示すようにJavaFXウィンドウを生成します。