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

  • SEARCH
  • Home
  • 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 8186113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:04:58+00:00 2026-06-07T02:04:58+00:00

Here is a SSCCE demonstrating how to put a Button into the TableView column.

  • 0

Here is a SSCCE demonstrating how to put a Button into the TableView column. It works but with little unpleasant behavior. When the table rows are scrolled down by mouse using the scroll bar, the new rendered buttons are not shown immediately. They are shown only when the mouse is released and then moved. I think there is another more elegant way of displaying the button in the table column and when clicked doing some stuff related to the selected row. Any suggestions?

import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.StackPaneBuilder;
import javafx.stage.Stage;
import javafx.util.Callback;

public class ButtonDemo extends Application {

    private TableView<Person> personTable = new TableView<>();
    private TableColumn<Person, String> nameCol = new TableColumn<>("name");
    private TableColumn<Person, Double> salaryCol = new TableColumn<>("salary");
    private TableColumn<Person, String> actionCol = new TableColumn<>("action");

    @Override
    public void start(Stage primaryStage) {
        ObservableList<Person> data = FXCollections.observableArrayList();
        for (int i = 0; i < 40; i++) {
            data.add(new Person("person_" + i, i * 100d));
        }

        nameCol.setCellValueFactory(new PropertyValueFactory<Person, String>("name"));
        salaryCol.setCellValueFactory(new PropertyValueFactory<Person, Double>("salary"));
        actionCol.setCellValueFactory(new PropertyValueFactory<Person, String>("name")); // "name" here is for just to render the column

        Callback<TableColumn<Person, String>, TableCell<Person, String>> printColumnCellFactory = //
                new Callback<TableColumn<Person, String>, TableCell<Person, String>>() {

            @Override
            public TableCell call(final TableColumn param) {
                final TableCell cell = new TableCell() {

                    @Override
                    public void updateItem(Object item, boolean empty) {
                        super.updateItem(item, empty);
                        if (empty) {
                            setText(null);
                            setGraphic(null);
                        } else {
                            final Button btnPrint = new Button("print name");
                            btnPrint.setOnAction(new EventHandler<ActionEvent>() {

                                @Override
                                public void handle(ActionEvent event) {
                                    param.getTableView().getSelectionModel().select(getIndex());
                                    Person item = personTable.getSelectionModel().getSelectedItem();
                                    if (item != null) {
                                        System.out.println(item.getName());
                                    }
                                }
                            });
                            setGraphic(btnPrint);
                            setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
                        }
                    }
                };
                return cell;
            }
        };
        actionCol.setCellFactory(printColumnCellFactory);

        personTable.setItems(data);
        personTable.getColumns().addAll(nameCol, salaryCol, actionCol);
        StackPane root = StackPaneBuilder.create().children(personTable).build();
        primaryStage.setScene(new Scene(root, 300, 250));
        primaryStage.show();
    }

    public class Person {

        private String name;
        private Double salary;

        public Person(String name, Double salary) {
            this.name = name;
            this.salary = salary;
        }

        public String getName() {
            return name;
        }

        public Double getSalary() {
            return salary;
        }
    }

    public static void main(String[] args) {
        launch(args);
    }
}
  • 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-07T02:05:00+00:00Added an answer on June 7, 2026 at 2:05 am

    Upgrading to version 2.1 resolved the problem.

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

Sidebar

Related Questions

Here is the code in a function I'm trying to revise. This example works
Here is the code: create table `team`.`User`( `UserID` bigint NOT NULL AUTO_INCREMENT , `Username`
Here is my SQL script CREATE TABLE tracks( track_id int NOT NULL AUTO_INCREMENT, account_id
Hi if You put JComboBox in JTable and String[] array to JComboBox everything works
I asked this before, but only theoretically, without an SSCCE. Now, I've created one,
I have a table with about 150 rows in it. These are the data
Here's a query that works fine: SELECT rowid as msg_rowid, a, b, c FROM
Here's a problem I ran into recently. I have attributes strings of the form
Here is a simplification of my database: Table: Property Fields: ID, Address Table: Quote
here's an SSCCE: import java.awt.Color; import java.awt.Dimension; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JButton; import

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.