You see, I'm a student and I'm doing a math program, the point is that, for this, the user enters a value of n (5, for example) and the program must display the values of 0 to n in different TextFields (with a limit of 6), for example, if the user enters 5 as the value of n, the program should display the values: 0,1,2,3,4,5 in 6 different TextFields
I use SceneBuilder and IntelliJ, so I put the TextFields in SceneBuilder directly. What I came up with was to use a for:
int n = Integer.parseInt(txtN.getText());
for(int x=0;x<=n;x++){
System.out.println(x);
}
}
If you have any other suggestions other than using a for, I'll read them :(
add nodes with for loop
I suggest node
Text
instead ofTextField
as node otherwise it won't be edited. Text is plain text not directly editable by the user. The same line is commented out but creates a new text instead of textfield . The program uses the same for loop , but in a ChangeListener . You should note that this approach does not check whether it is a valid int or not . For this there is TextFormatter . Every time a value is changed, the children must be cleaned withgetChildren().clear()
This is a working javafx app in a single class that you can check out . App.java