0

I'm trying to change the text of a textfield being handled by another class.

public String updateAddress() {
    webEngine.getLoadWorker().stateProperty().addListener((observable, oldValue, newValue) -> {
         if (Worker.State.SUCCEEDED.equals(newValue)) {
             Client.addressBar.setText(webEngine.getLocation());     
         }
     });
    return null;
}

but this only works if the textfield is static.

When I try to create a method that updates the textfield Java just crashes. I'm trying to create a multi tabbed browser so this method would update the address bar when the current tab I'm on is selected.

zero323
  • 322,348
  • 103
  • 959
  • 935
Lodington
  • 13
  • 3
  • can you post the error you're getting? Also, what is `Client`? I'm confused by the capital letter: by convention `addressBar` would be a static field, so I'm not sure what you're working with here A little more context would be useful. – MikaelF Apr 27 '18 at 20:56
  • Client is the main class that handles the scene. the address bar is located in the client class. java just crashes when i run this and eclipse doesnt log any errors – Lodington Apr 28 '18 at 05:52
  • What do you mean "Java just crashes"? Don't you get a [stack trace](https://stackoverflow.com/q/3988788/2775450)? – James_D Apr 30 '18 at 12:31
  • No nothing at all its the weirdest thing eclipse comes back and says the program was terminated in console..... and nothing was logged. – Lodington Apr 30 '18 at 12:35

1 Answers1

0

Into the action you set a tab as visible/selected you can put this code to set the address bar.

justcode
  • 1,562
  • 3
  • 14
  • 25
  • I have a class called "browser" and a class called "client" client is where the address bar is held and the browser class holds the web engine. i dont know if i can pass the webengine across to the other class like that.... – Lodington Apr 27 '18 at 19:54
  • @Lodington you have a class where you create all the tabs and put them into a list? Is not from this class where you set the selected tab? You can pass the client class to this controller class during the controller class construction and from the every time a user selects a tab set the address bar name like client.setAddressBar("name") – justcode Apr 27 '18 at 19:57
  • i have the source here https://stackoverflow.com/questions/50007277/not-able-to-update-url-and-update-webview?noredirect=1#comment87060394_50007277 – Lodington Apr 27 '18 at 20:02