[JAVA] [Personal memorandum] Eclipse button placement control object generation
◎ Execution environment
・ Windows7
・ Eclipse4.6 Neon
◎ Code
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); //Specify width as 500
stage.setHeight(300); //Specify height as 300
Button button1 = new Button("1"); //Generate 6 button controls
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); //Width 300,Specify height as 100
button2.setPrefSize(300,100);
button3.setPrefSize(300,100);
button4.setPrefSize(300,100);
button5.setPrefSize(100,50); //Width 100,Specify height as 50
button6.setPrefSize(100,50);
GridPane subPane = new GridPane(); //Create GridPane object
subPane.setConstraints(button4,0,0); //0,Placement specified at position 0
subPane.setConstraints(button5,1,0); //1,Placement specified at position 0
subPane.setConstraints(button6,1,1); //1,Placement designation at position 1
subPane.getChildren().addAll(button4,button5,button6);
//4,5,6 added to subPane
GridPane root = new GridPane(); //Create an object that will be the root pane
GridPane.setConstraints(button1,0,0); //Specify button placement
GridPane.setConstraints(button2,1,0);
GridPane.setConstraints(button3,0,1);
GridPane.setConstraints(subPane,1,1); //Specify the position of subPane
root.getChildren().addAll(button1,button2,button3,subPane);
//SubPane in the root pane,Add everything
Scene scene = new Scene(root);
//Create a scene object
stage.setScene(scene); //Place the scene on the stage
stage.show(); //Show application window
}
public static void main(String[] args){
launch();
}
}