0

I want to update the value on the JavaFx textfield after an event. I have a RootScreen which opens a popup and in that popup i have a listview . When a user select the item on that listview, it should update the value on the texfield in RootScreen . This is the code for the action on the button which is present on every list item. Every listItem also has a TEXTFIELD and button to select it. I want the value on the TEXTFIELD to be on the texfield in RootScreen.Kindly see the uppercase and lowercase as i tried to make it as understandable as possible.

    public void initialize() {
            button.setOnAction(event -> {
                source = select.getParent();
//walletname is the name i want on textfield.
                walletName = textField.getText();
                getWalletName(walletName);
                Stage stage = (Stage) source.getScene().getWindow();
                stage.close();




            });

        }
        private void getWalletName(String walletName){

            profilePopup.SetText(walletName,rootScreenController);

        }

The SetText method is in the Popup View Class. The code for SetText method.

public void SetText(String walletName, OnClick onClick){
        onClick.onMouseClicked(walletName);
   }

I have a interface OnClick, which has a onMouseClicked method . The interface i implemented in RootScreen

public interface OnClick {
      void onMouseClicked(String name);


}

This is how I am overriding the method in the interface.

@Override
    public void onMouseClicked(String walletName) {
textfield.setText(walletname);
    }

But its not updating the value on the textfield. I am new in java, so I am not sure what to do here.

shraj.t
  • 9
  • 4
  • Check out my answer to [this question](https://stackoverflow.com/questions/14187963/passing-parameters-javafx-fxml/51050736#51050736). It may help you figure this out. – Zephyr Sep 23 '18 at 01:21
  • 1
    btw: the inline markup in your question is __TERRIBLE__ - highlighting by upper case letters plus adding a code tag (which is for ... code, not words, not even class/field names) makes is very hard to read – kleopatra Sep 24 '18 at 11:32

2 Answers2

0

If you have a popup screen that populates the information from the ListView, I think it is best that if the ListView entry is an Object or an Object in a collection. That is the only way you can separate each entry on the ListView - pulling the information from the object instead of deriving it from the ListView a a singular item.

rizcan
  • 57
  • 1
  • 4
0

Here is a runnable example I think you are way over complicating this you can use the .setOnMouseClicked functionality to simplify this

public class Main extends Application {

    public static void main(String[] args) { launch(args); }

    @Override
    public void start(Stage primaryStage) {
        TextField textField = new TextField("Not the same");

        ListView<String> listView = new ListView<>();
        listView.getItems().add("Item 1");
        listView.getItems().add("Item 2");
        listView.getItems().add("Item 3");
        listView.setOnMouseClicked(event -> {//You can change this if need be
            textField.setText(listView.getSelectionModel().getSelectedItem());
        });

        VBox vBox = new VBox();
        vBox.getChildren().addAll(listView, textField);

        Scene scene = new Scene(vBox);
        primaryStage.setScene(scene);
        primaryStage.show();
    }
}

for more information on listView check out this you also may want to look at the object properties here

Matt
  • 3,052
  • 1
  • 17
  • 30