LoginSignup
0
0

More than 5 years have passed since last update.

【個人的備忘録】Eclipseによる javafxのボタンの配置 コントロール オブジェクトの生成

Posted at
◎実行環境
・windows7
・Eclipse4.6 Neon
◎コード
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;


public class Main extends Application {
    public void start(Stage stage){
        stage.setWidth(500);  //横幅を500に指定
        stage.setHeight(300);  //高さを300に指定


        Button button1 = new Button("1");  //ボタンコントロールを6つ生成
        Button button2 = new Button("2");
        Button button3 = new Button("3");
        Button button4 = new Button("4");
        Button button5 = new Button("5");
        Button button6 = new Button("6");


        button1.setPrefSize(300,100);  //横幅を300, 高さを100に指定
        button2.setPrefSize(300,100);
        button3.setPrefSize(300,100);
        button4.setPrefSize(300,100);
        button5.setPrefSize(100,50);  //横幅を100, 高さを50に指定
        button6.setPrefSize(100,50);

        GridPane subPane = new GridPane();   //GridPaneオブジェクトを生成
        subPane.setConstraints(button4,0,0);  //0,0の位置に配置指定
        subPane.setConstraints(button5,1,0);  //1,0の位置に配置指定
        subPane.setConstraints(button6,1,1);  //1,1の位置に配置指定


        subPane.getChildren().addAll(button4,button5,button6);
      
     //4,5,6をsubPaneに追加

        GridPane root = new GridPane();   //ルートペインとなるオブジェクトを生成
        GridPane.setConstraints(button1,0,0);  //ボタンの配置を指定
        GridPane.setConstraints(button2,1,0);
        GridPane.setConstraints(button3,0,1);
        GridPane.setConstraints(subPane,1,1);  //subPaneの位置を指定

        root.getChildren().addAll(button1,button2,button3,subPane);

     //ルートペインにsubPane,すべてを追加

        Scene scene = new Scene(root);
     //シーンオブジェクトを生成


        stage.setScene(scene);  //ステージにシーンを配置
        stage.show();       //アプリケーションウィンドウを表示
    }






    public static void main(String[] args){
        launch();
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0