Forum Stats

  • 3,854,655 Users
  • 2,264,394 Discussions


Got The Roster On My Chat Application

edited Sep 15, 2016 9:59AM in JavaFX 2.0 and Later

Hello Everyone,

                              I have some query regarding get the roster. Kindly tell me the best idea to get the roster?? i have used Listview, Vbox ,TableView but i don't know which one is best ?

which one give the fast performance to get the roster? & Is scenebuilder components object is static forever in the code??.

and the most important question :

If i want to show my roster on my scene builder then it will happen after i put some handler, I want to when click my button who call my next scene all the roster comes on next scene automatically.

Kindly give all the responses regarding above mention questions ASAP.



  • bekwam
    bekwam Member Posts: 6
    edited Sep 15, 2016 9:59AM


    I would use a TableView even if you have only one TableColumn to show.

    Start by creating a .fxml / Controller pair.  The following screenshot shows Scene Builder with a VBox containing a TableView and a refresh Button.


    In the Controller, hookup the TableView, TableColumn, and refresh action.  Provide an implementation of refresh that pulls in the data.  The Task wrapper is very important to keep your application responsive.

    Participant is a domain object with a single field "screenName".

    public class SimpleTableController {

       TableColumn<Participant, String> tcScreenName;

       TableView<Participant> tblParticipants;

       public void initialize() {

       tcScreenName.setCellValueFactory(new PropertyValueFactory<Participant,String>("screenName"));


       public void refresh() {

      Task<List<Participant>> task = new Task<List<Participant>>() {

       protected List<Participant> call() throws Exception {

       return fetchData();


       protected void succeeded() {


       tblParticipants.getItems().addAll( fetchData() );



       new Thread(task).start();


       private List<Participant> fetchData() {

      List<Participant> participantList = new ArrayList<>();

      participantList.add( new Participant("WALK" + counter++) );

      participantList.add( new Participant("DAVI" + counter++) );

      participantList.add( new Participant("JNYG" + counter++) );

       return participantList;


       private int counter = 1;


    And from your button handler, load the screen using the following code block.  Note the refresh() call made on the Controller to load the initial data set.

    try {

      FXMLLoader fxmlLoader = new FXMLLoader(this.getClass().getResource("/SimpleTable.fxml"));

      Parent p = fxmlLoader.load();

      SimpleTableController c = fxmlLoader.getController();

      Scene scene = new Scene( p );

      Stage stage = new Stage();

      stage.setTitle( "SimpleTableApp - TableView");

      stage.setWidth( 667 );

      stage.setHeight( 375 );


      stage.setOnShown( (windowEvent) -> c.refresh() );;

    } catch(Exception exc) {



    Good luck.
This discussion has been closed.