Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8153903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:10:01+00:00 2026-06-06T16:10:01+00:00

I would like to know how do I populate a TableView with data… All

  • 0

I would like to know how do I populate a TableView with data… All the examples I have seen creates a TableView with columns and everything and add it to the scene. All done in the java code itself.

What I want to know: if I design my “form” in JavaFx Scene builder. Defining all the tables and columns in there. How do I access it to populate it from java? Or if someone can point me to a proper tutorial on this please.

I have defined my form in JavaFx Scene Builder – only a TableView with 3 Columns

<?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.paint.*?>

<AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="288.0" prefWidth="293.0" xmlns:fx="http://javafx.com/fxml">
<children>
    <TableView fx:id="tableView" layoutX="35.0" layoutY="28.0" prefHeight="200.0" prefWidth="227.0">
    <columns>
        <TableColumn prefWidth="75.0" text="UserId" fx:id="UserId" />
        <TableColumn prefWidth="75.0" text="UserName" fx:id="UserName" />
        <TableColumn prefWidth="75.0" text="Active" fx:id="Active" />
    </columns>
    </TableView>
</children>
</AnchorPane>

I have my data in a ResultSet in my Java code.

ResultSet rs = c.createStatement().executeQuery(SQL);

I need to populate the TableView.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T16:10:03+00:00Added an answer on June 6, 2026 at 4:10 pm

    To access to tableview you need to define a controller of your FXML page. Add

    fx:controller="path.to.MyController"
    

    attribute to the AnchorPane in FXML file. Then create the controller and link TableView, TableColumns from FXML file by putting @FXML annotation in front of these variables:

    package path.to;
    
    public class MyController implements Initializable {
    
        @FXML private TableView<User> tableView;
        @FXML private TableColumn<User, String> UserId;
        @FXML private TableColumn<User, String> UserName;
        @FXML private TableColumn<User, String> Active;
    
        @Override
        public void initialize(URL location, ResourceBundle resources) {
            UserId.setCellValueFactory(new PropertyValueFactory<User, String>("id"));
            UserName.setCellValueFactory(new PropertyValueFactory<User, String>("name"));
            Active.setCellValueFactory(new PropertyValueFactory<User, String>("active"));
    
            tableView.getItems().setAll(parseUserList());
        }
        private List<User> parseUserList(){
            // parse and construct User datamodel list by looping your ResultSet rs
            // and return the list   
        }
    }
    

    The tableview is populated in the initialize method. Note that in controller we are not creating new tableview or tablecolumns, since they are already created whlle the FXML file is being loaded. Also note that the TableView and Tablecolumn variable names must be the same with fx:id values in the corresponding FXML file. So while UserId, UserName and Active names are not convenient namings, change them both in FXML file and in Controller to names like userIdCol, userNameCol and userActiveCol respectively.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to know how. I have looked at this topic , and
I'd like to add search functionality to a TableView in my app. I populate
I would like to know the best way to populate an object that has
I have a typed dataset in my project. I would like to populate a
I have a ListView and a DataTable and I would like to know how
i would like to know how can i populate/load the UIPageViewController ( the based
I have 2 tables, Provinces and Districts. I would like to populate a select
i would like know some reference. I know i can googling it. but prefer
Would like to know what a programmer should know to become a good at
Would like to know the c# code to actually retrieve the IP type: Static

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.