Javafx-layout-flowpane
提供:Dev Guides
JavaFX-FlowPane
アプリケーションでフローペインを使用すると、すべてのノードがフローにラップされます。 水平フローペインはペインの要素をその高さでラップし、垂直フローペインは要素をその幅でラップします。
パッケージ javafx.scene.layout の FlowPane という名前のクラスは、フローペインを表します。 このクラスには、以下を含む7つのプロパティが含まれます-
- alignment -このプロパティは、フローペインのコンテンツの配置を表します。 このプロパティは、セッターメソッド* setAllignment()*を使用して設定できます。
- columnHalignment -このプロパティは、垂直フローペイン内のノードの水平方向の配置を表します。
- rowValignment -このプロパティは、水平フローペイン内のノードの垂直方向の配置を表します。
- Hgap -このプロパティはダブルタイプで、フローペインの行/列間の水平方向のギャップを表します。
- Orientation -このプロパティは、フローペインの方向を表します。
- Vgap -このプロパティはダブルタイプで、フローペインの行/列間の垂直方向のギャップを表します。
例
次のプログラムは、 FlowPane レイアウトの例です。 これでは、水平フローペインに4つのボタンを挿入しています。
このコードを FlowPaneExample.java という名前のファイルに保存します。
import javafx.collections.ObservableList;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.FlowPane;
import javafx.scene.shape.Sphere;
import javafx.stage.Stage;
public class FlowPaneExample extends Application {
@Override
public void start(Stage stage) {
//Creating button1
Button button1 = new Button("Button1");
//Creating button2
Button button2 = new Button("Button2");
//Creating button3
Button button3 = new Button("Button3");
//Creating button4
Button button4 = new Button("Button4");
//Creating a Flow Pane
FlowPane flowPane = new FlowPane();
//Setting the horizontal gap between the nodes
flowPane.setHgap(25);
//Setting the margin of the pane
flowPane.setMargin(button1, new Insets(20, 0, 20, 20));
//Retrieving the observable list of the flow Pane
ObservableList list = flowPane.getChildren();
//Adding all the nodes to the flow pane
list.addAll(button1, button2, button3, button4);
//Creating a scene object
Scene scene = new Scene(flowPane);
//Setting title to the Stage
stage.setTitle("Flow Pane 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 FlowPaneExample.java
java FlowPaneExample
実行時に、上記のプログラムは以下に示すようにJavaFXウィンドウを生成します。