I have an ArrayList from TextField , I need to delete a TextField in the program (there is no problem with this), but this deleted item still remains on the application screen.

Tell me, please, how can I update the screen, or can I solve the problem differently?

  • give an example code. How do you delete an item? - Axifive
  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Axifive

1 answer 1

Probably you assign a null value to the pointer, it does not remove the TextField if it has been added to the scene. To remove an element from the panel, you must directly call the remove() method.

Here is an example to understand (when you click on a button, the button is removed from the panel):

 public class Main extends Application { @Override public void start(Stage primaryStage) throws Exception{ primaryStage.setTitle("Remove Button"); final StackPane root = new StackPane(); final Button btn = new Button(); btn.setLayoutX(100); btn.setLayoutY(80); btn.setText("Remove me=)"); btn.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { root.getChildren().remove(btn); } }); root.getChildren().add(btn); primaryStage.setScene(new Scene(root, 300, 275)); primaryStage.show(); } public static void main(String[] args) { launch(args); } }