JAVAFX - unable to add items to listview


Question

I have a Tab called chat. Inside this Tab I have a list of users as ListView<string>. The content of this ListView was loaded from FXML file using:

FXMLLoader.load(getClass().getResource("chat.fxml"))

I am trying to add items to my listview using java, but when I open the GUI, chat tab, the items I add does not get displayed in the users listview.

One of the ways I tried was:

List<String> values = Arrays.asList("one", "two", "three");
listOfUsers.setItems(FXCollections.observableList(values));

I have tried other ways as well, but nothing seems to work. I'd appreciate your help.

1
1
6/30/2015 4:39:17 AM

Accepted Answer

thanks guys..
the problem was that my listView of users was created by the FXML loader, and then by mistake i initialized it again in the java code, so all was needed is deleting the row:

listOfUsers=new ListView<String>();
3
3/17/2013 2:29:41 PM

the file chat.fxml has fx:controller?!

You need...

xmlns:fx="http://javafx.com/fxml" fx:controller="DIRECTORY.FILE" //FILE.java

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon