[Personal memorandum] Effect of javafx VBox / setOnAction by Eclipse, etc.

◎ Sample code
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class Sample extends Application {
    public void start(Stage stage){
            stage.setWidth(500);    //Specify width
            stage.setHeight(500);    //Specify height
            
            Button button1 = new Button("A");    //Add button attribute
            Button button2 = new Button("B");
            Button button3 = new Button("C");
            Button button4 = new Button("D");
            button1.setOnAction(event -> System.out.println("OK!"));    //Output event processing with setOnAction
            button2.setOnAction(event -> System.out.println("NICE!"));
            button3.setOnAction(event -> System.out.println("YES!"));
            button4.setOnAction(event -> System.out.println("Goodluck!"));
            
            
            VBox box = new VBox(5);
            box.getChildren().addAll(button1,button2,button3,button4);    //Put the button attribute in the box to recognize it

            stage.setScene(new Scene(box));    //Display box in Scene
            stage.show()    //Output screen
            
        public static void main(String[] args) {
            launch();

When you run it, it looks like this gazou.jpg Event processing is output when you click in order from the top gazou2.jpg

Recommended Posts

[Personal memorandum] Effect of javafx VBox / setOnAction by Eclipse, etc.
[Personal memorandum] Button layout created with javafx in Eclipse (in the case of HBox / VBox)
Introduction of javaFX in Eclipse (April 2020)
A memorandum of personal phpenv install