1 Reply Latest reply on Apr 28, 2014 9:48 AM by skytrace

    How can I update my List with TextField's on UI


      Hello my dears!

      Could you please tell me what I do wrong for updating my lists of TextFields. I have a small application which can add textfield via form with elements:  TextField for phone number, TextField for name and button Save. Also, I have a combobox menu, for selecting a contact by name, and delete him. It is something like a small phone book number.

      I have to classes, in first class I made displaying UI elements and showing contacts from storage. In second class I made my other features, like: add contact, delete him, display all contacts, display all name of contacts in combobox.

      In my Main class, I wrote next code:


      Listing 1.

      public class Main extends Application {
          public void start(final Stage primaryStage) throws Exception {
              root = new Pane();
              // action for remove contact
              removeContact.setOnAction(new EventHandler<ActionEvent>() {
                  public void handle(ActionEvent actionEvent) {
                      try {
                          String contact = comboBox.getSelectionModel().getSelectedItem().toString();
                      } catch (Exception e) {
              root.getChildren().addAll(..., save, comboBox, removeContact);
              primaryStage.setScene(new Scene(root, 400, 400));



      And my Modules class with getListContacts() method:


      Listing 2.

      public static List<TextField> getListFields() {
              listFields = new ArrayList<TextField>();
              List<String> list = parseXML();
              int y = 130;
              for (int i = 0; i < list.size(); i++) {
                  listFields.add(new TextField(list.get(i)));
                  listFields.get(i).setLayoutY(y += 30);
              return listFields;


      In this method, I getting all contacts from my xml file, and display them in Pane in format like:






      So, I describe you mechanism how it works.

      1. I select from Combobox some contact (Liza)  (Pic1) (Pic2)

      2. push removeContact button

      3. When I clicked removeContact button, I getting contact which I selected in combobox (Listing 1, line: 12).

      4. Then I remove this contact from storage (Listing 1, line: 13).

      5  And redisplaying all my contacts from storage (Listing 1, line: 14) (Pic3).


      But, how you can see in Pic3, contact Liza was removed, but last contact from list (Nansy), is duplicate. Could you tell me please, what I do wrong and maybe you can propose me some solution?


      PS: Thanks.