0

I'm trying to display a ListView but it does not work. Here is where the variable where the data I want to display is initialized :

public static ListView<String> usersList = new ListView<String>();

Here is where it is supposed to be displayed :

<listView fx:id="usersList" prefHeight="307.0" prefWidth="306.0" />

Here is where the FXML file is stocked :

root = FXMLoader.Load(getClass().getRessource("/View/UsersListWindowFx.fxml"));

And finally, here is where I add elements in usersList :

public void initialize(URL location, RessourceBundle ressources) {
    List<String> usersListData = UserDataBase.getAllActiveUsersUsername();
    ObservableList<String> names = FXCollections.observableArrayList(usersListData);
    usersList.setItems(names);
}

I already check, UserDataBase.getAllActiveUsersUsername() does not return an empty list and there is various String in it, but despite that usersList still does not display.

Please, do you have any idea of what could cause this problem ?

TitouanL
  • 3
  • 1

1 Answers1

1

When you use fx:id in fxml file you don't need to make new instance of ListView you just need to add @FXML annotation like this:

@FXML
private ListView usersList;

another thing you need to know is that you can't use static in a fxml field so remove it.