Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How To get TableView Row data using an index?

Lucio TepeAug 9 2017 — edited Aug 9 2017

Hi there. I'll need to get the TableRow Data (in a TableView (JavaFX)) using the index of a specific row. For exemple: there is a TableView with 3 rows and each row with 3 columns. I want to get the 3 columns of row number 2 (index of row 2 is 1). I saw in the WEB that i can get the entire row and convert it to String. Take a look below:

myTableView.setRowFactory (tv ->

  {

     TableRow<ObservableList> myRow = new TableRow<>();

     theRow.setOnMouseClicked (event ->

     {

        if (event.getClickCount() == 1 && (!myRow.isEmpty()))

        {

           int myIndex =

               myTableView.getSelectionModel().getSelectedIndex();

           String myRowData =

               myTableView.getItems().get(myIndex).toString();

        }

     });

        return myRow;

  });

The code above run ok. I get the Index correctly. But the content of myRowData isn't correct. Can anyone help me?

Tks.

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 6 2017
Added on Aug 9 2017
0 comments
1,779 views