#author("2018-05-12T05:29:08+00:00","default:haikikyou","haikikyou")
#author("2018-05-12T10:56:46+00:00","default:haikikyou","haikikyou")
#contents

* GridPane [#db5761be]

- 行と列で区切られたレイアウトを構築する

#ref(javafx-container-gridpane.png)

&label(sample){サンプル};  
&label(sample){サンプル};  GridPaneにノードを配置する

&ref(./SampleGridPane.java);

#geshi(java){{{
package sample;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;

public class SampleGridPane extends Application {

	/**
	 * Initialize stage and start scene.
	 *
	 * @param primaryStage
	 * @throws Exception
	 */
	@Override
	public void start(Stage primaryStage) throws Exception {
		GridPane gridPane = new GridPane();

		Button button1 = new Button("Button1");
		button1.setPrefSize(Double.MAX_VALUE, 100);
		Button button2 = new Button("Button2");
		button2.setPrefSize(100, 100);
		Button button3 = new Button("Button3");
		button3.setPrefSize(100, 100);

		// Set rowIndex and colIndex with add method.
		gridPane.add(button1, 0, 0, 3, 1);
		gridPane.add(button2, 0, 1);
		gridPane.add(button3, 0, 2);

		Button button4 = new Button("Button4");
		button4.setPrefSize(Double.MAX_VALUE, 100);
		Button button5 = new Button("Button5");
		button5.setPrefSize(100, 100);
		Button button6 = new Button("Button6");
		button6.setPrefSize(100, 100);

		gridPane.add(button4, 1, 1, 2, 1);

		// Use static setter method.
		GridPane.setRowIndex(button5, 2);
		GridPane.setColumnIndex(button5, 1);

		// Use static convinience method.
		GridPane.setConstraints(button6, 2, 2);
		gridPane.getChildren().addAll(button5, button6);


		// Create a scene
		Scene scene = new Scene(gridPane, 300, 300);
		primaryStage.setScene(scene);

		// Show window.
		primaryStage.show();
	}

	/**
	 * Launch application.
	 *
	 * @param args
	 */
	public static void main(String[] args) {
		launch(args);
	}
}
}}}

&label(info){補足};
- 9つのグリッドにボタンを配置する。
- 1行目は、(0,0)をcolspan=3で、2行目は、(1,1)をcolspan=2として配置している。
- グリッドへのノード配置は、インスタンスメソッドaddを使用する方法やstaticメソッドで行・列のポジション指定してノード追加する方法がある。

* 参考リンク [#t6e94d52]

- https://docs.oracle.com/javase/jp/8/javafx/api/javafx/scene/layout/GridPane.html
- https://docs.oracle.com/javase/jp/8/javafx/layout-tutorial/builtin_layouts.htm


トップ   一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
目次
ダブルクリックで閉じるTOP | 閉じる
GO TO TOP