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 8208071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:13:00+00:00 2026-06-07T09:13:00+00:00

I use javafx2 control TableView to dispay records in the database(I have 20 records

  • 0

I use javafx2 control TableView to dispay records in the database(I have 20 records now).
And when display the record,I want to add button in each row.
so I search lots of article use google,and write some code below.

the key code is:

    protected void updateItem(Long item, boolean empty) {
    super.updateItem(item, empty);
    if(empty) {
        setText(null);
        setGraphic(null);
    } else {
        final Button button = new Button("modifty");
        setGraphic(button);
        setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
    }
}

I debug this code,the param “empty” would never be “false”,
so the button would never be display in the table view,

can anyone help me? thanks

below is the complete code(java and fxml):

java:

    package com.turbooo.restaurant.interfaces.javafx;

import java.io.IOException;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.ResourceBundle;

import javafx.beans.property.SimpleStringProperty;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ContentDisplay;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.util.Callback;

import com.turbooo.restaurant.domain.Customer;
import com.turbooo.restaurant.domain.CustomerRepository;
import com.turbooo.restaurant.interfaces.facade.dto.CustomerDto;
import com.turbooo.restaurant.interfaces.facade.dto.assembler.CustomerDtoAssembler;
import com.turbooo.restaurant.util.ContextHolder;
import com.turbooo.restaurant.util.UTF8Control;

public class CustomerController implements Initializable {

    @FXML
    private TableView<CustomerDto> customerTableView;

    @Override
    public void initialize(URL arg0, ResourceBundle arg1) {


        TableColumn<CustomerDto, Long> idCol = new TableColumn<CustomerDto, Long>("id");
        idCol.setCellValueFactory(
            new PropertyValueFactory<CustomerDto,Long>("id")
        );

        TableColumn<CustomerDto, String> nameCol = new TableColumn<CustomerDto, String>("name");
        nameCol.setMinWidth(100);
        nameCol.setCellValueFactory(
            new PropertyValueFactory<CustomerDto,String>("name")
        );

        TableColumn<CustomerDto, String> birthdayCol = new TableColumn<CustomerDto, String>("birthday");
        birthdayCol.setCellValueFactory(
                new Callback<TableColumn.CellDataFeatures<CustomerDto, String>, ObservableValue<String>>() {
                    @Override
                    public ObservableValue<String> call(TableColumn.CellDataFeatures<CustomerDto, String> customer) {
                        if (customer.getValue() != null) {
                            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                            return new SimpleStringProperty(sdf.format(customer.getValue().getBirthday()));
                        } else {
                            return new SimpleStringProperty("");
                        }
                    }
                });

        TableColumn<CustomerDto, Long> actionCol = new TableColumn<CustomerDto, Long>("action");
        actionCol.setCellFactory(
                new Callback<TableColumn<CustomerDto,Long>, TableCell<CustomerDto,Long>>() {
                    @Override
                    public TableCell<CustomerDto, Long> call(TableColumn<CustomerDto, Long> arg0) {
                        final TableCell<CustomerDto, Long> cell = new TableCell<CustomerDto, Long>() {
                            @Override
                            protected void updateItem(Long item, boolean empty) {
                                super.updateItem(item, empty);
                                if(empty) {
                                    setText(null);
                                    setGraphic(null);
                                } else {
                                    final Button button = new Button("modifty");
                                    setGraphic(button);
                                    setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
                                }
                            }
                        };

                        return cell;
                    }
                });


        //TODO add button column

        customerTableView.getColumns().addAll(idCol, nameCol, birthdayCol, actionCol);       

        loadData();

    }

    public void loadData() {
        CustomerRepository cusRepo = (CustomerRepository)ContextHolder.getContext().getBean("customerRepository");

        List<Customer> customers = cusRepo.findAll();
        CustomerDtoAssembler customerDTOAssembler = new CustomerDtoAssembler();
        List<CustomerDto> customerDtos = customerDTOAssembler.toDTOList(customers);

        ObservableList<CustomerDto> data = FXCollections.observableArrayList(customerDtos);
        customerTableView.setItems(data);        
    }


    public void showNewDialog(ActionEvent event) {
        ResourceBundle resourceBundle = ResourceBundle.getBundle(
                "com/turbooo/restaurant/interfaces/javafx/customer_holder",
                new UTF8Control());

        Parent container = null;
        try {
            container = FXMLLoader.load(
                    getClass().getResource("customer_holder.fxml"), 
                    resourceBundle);

        } catch (IOException e) {
            e.printStackTrace();
        }

        container.setUserData(this);    //pass the controller, so can access LoadData function in other place later

        Scene scene = new Scene(container, 400, 300);
        Stage stage = new Stage();
        stage.setScene(scene); 
        stage.initModality(Modality.APPLICATION_MODAL);
        stage.show();

    }
}

fxml:

    <?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.*?>

<BorderPane prefHeight="345.0" prefWidth="350.0" xmlns:fx="http://javafx.com/fxml" fx:controller="com.turbooo.restaurant.interfaces.javafx.CustomerController">
  <center>
    <TableView fx:id="customerTableView" prefHeight="200.0" prefWidth="200.0" />
  </center>
  <top>
    <HBox alignment="CENTER_LEFT" prefHeight="42.0" prefWidth="350.0">
      <children>
        <Button text="new" onAction="#showNewDialog"/>
        <Separator prefHeight="25.0" prefWidth="13.0" visible="false" />
        <Button text="modify" />
        <Separator prefHeight="25.0" prefWidth="15.0" visible="false" />
        <Button text="delete" />
      </children>
    </HBox>
  </top>
</BorderPane>
  • 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-07T09:13:02+00:00Added an answer on June 7, 2026 at 9:13 am

    You haven’t set a cellValueFactory for your action column, so it is always empty.
    A simple way to do this is just to set the cell value to the id of the record.

    actionCol.setCellValueFactory(
        new PropertyValueFactory<CustomerDto,Long>("id")
    );
    

    Additionally, I created a simple example for creating a table with Add buttons in it, which you could reference if needed.

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

Sidebar

Related Questions

I have this easy little form in my JavaFX application. I want to use
Use case: I've just entered insert mode, and typed some text. Now I want
Use case: we have some project meta-data files which we want tracked, but are
I have problem, when I want add Node to my GUI from other Thread.
Use Flex 4.5.1 and when add icons to the button is so curve effect
use Control::CLI; $cli = new Control::CLI('SSH'); $cli->connect(Host=>'10.10.10.10',Username=>'user',Password=>'pwd'); $cli->waitfor('>'); $cli->print('Show XXXXXXXXXXXXXXXXXXXX| grep Active'); @f=$cli->waitfor('>'); print
I have installed JavaFX 2.0 SDK and now I would like to do an
At the moment I use QuickTime for Java to display video in a swing
I am developing a Java Swing application but I want to also use JavaFX
I have a HTML5 UI and a Java backend and want to avoid rebuilding

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.