I need to add an array of 20 buttons to a flow pane. I have the array created but can't seem to get all of the buttons show up. Why is it only adding one button?
public class Activity4 extends Application
{
@Override
public void start(Stage primaryStage)
{
Button[] btn = new Button[20];
for(int i=0; i<btn.length;i++)
{
btn[i] = new Button();
btn[i].setText("Safe!");
FlowPane root = new FlowPane();
root.getChildren().addAll(btn[i]);
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle("Button Blast!");
primaryStage.setScene(scene);
primaryStage.show();
btn[i].setOnAction(new EventHandler<ActionEvent>()
{
@Override
public void handle(ActionEvent event)
{
System.out.println("Hello World!");
}
});
}
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
