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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:52:03+00:00 2026-06-16T01:52:03+00:00

I try to use ComboxBoxTableCell without success. The content of the cell display the

  • 0

I try to use ComboxBoxTableCell without success.
The content of the cell display the right value for the attribute of an object. But when the combobox is displayed, all items are displayed with the toString object method and not the attribute.
I tryed to override updateItem of ComboBoxTableCell or to provide a StringConverter but nothing works.

Do you have some ideas to custom comboxbox list display in a table cell ?

I put a short example below to see quickly the problem. Execute the app and click in the cell, you will see the combobox with toString value of the object.

package javafx2;  

import javafx.application.Application;
import javafx.beans.property.adapter.JavaBeanObjectPropertyBuilder;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableColumn.CellDataFeatures;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.ComboBoxTableCell;
import javafx.stage.Stage;
import javafx.util.Callback;
import javafx.util.StringConverter;

public class ComboBoxTableCellTest extends Application {

    public class Product {
        private String name;
        public Product(String name) {
            this.name = name;
        }
        public String getName() { return name; }
        public void setName(String name) { this.name = name; }
    }

    public class Command {
        private Integer quantite;
        private Product product;
        public Command(Product product, Integer quantite) {
            this.product = product;
            this.quantite = quantite;
        }
        public Integer getQuantite() { return quantite; }
        public void setQuantite(Integer quantite) { this.quantite = quantite; }
        public Product getProduct() { return product; }
        public void setProduct(Product product) { this.product = product; }
    }

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage stage) throws Exception {
        Product p1 = new Product("Product 1");
        Product p2 = new Product("Product 2");
        final ObservableList<Product> products  = FXCollections.observableArrayList(p1, p2);
        ObservableList<Command> commands  = FXCollections.observableArrayList(new Command(p1, 20)); 

        TableView<Command> tv = new TableView<Command>();
        tv.setItems(commands);

        TableColumn<Command, Product> tc = new TableColumn<Command, Product>("Product");
        tc.setMinWidth(140);
        tc.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<Command,Product>, ObservableValue<Product>>() {

            @Override
            public ObservableValue<Product> call(CellDataFeatures<Command, Product> cdf) {
                try {
                    JavaBeanObjectPropertyBuilder<Product> jbdpb = JavaBeanObjectPropertyBuilder.create();
                    jbdpb.bean(cdf.getValue());
                    jbdpb.name("product");
                    return (ObservableValue) jbdpb.build();
                } catch (NoSuchMethodException e) {
                    System.err.println(e.getMessage());
                }
                return null;
            }
        });
        final StringConverter<Product> converter = new StringConverter<ComboBoxTableCellTest.Product>() {

            @Override
            public String toString(Product p) {
                return p.getName();
            }

            @Override
        public Product fromString(String s) {
                // TODO Auto-generated method stub
                return null;
            }
        };

        tc.setCellFactory(new Callback<TableColumn<Command,Product>, TableCell<Command,Product>>() {

            @Override
            public TableCell<Command, Product> call(TableColumn<Command, Product> tc) {
                return new ComboBoxTableCell<Command, Product>(converter, products) {
                    @Override
                    public void updateItem(Product product, boolean empty) {
                        super.updateItem(product, empty);
                        if (product != null) {
                            setText(product.getName());
                        }
                    }
                };
            }
        });

        tv.getColumns().add(tc);
        tv.setEditable(true);

        Scene scene = new Scene(tv, 140, 200);
        stage.setScene(scene);
        stage.show();
    }
}
  • 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-16T01:52:04+00:00Added an answer on June 16, 2026 at 1:52 am

    Desculpe-me Philippe Jean por respondê-lo em português, mas como não domino bem sua língua, achei melhor desta forma.

    Encontrei o mesmo problema que o seu e solucionei-o com a seguinte implementação.


    I found the same problem as yours and solved it with the following implementation.

    final ObservableList<Product> products  = FXCollections.observableArrayList(p1, p2);
    ObservableList<Command> commands  = FXCollections.observableArrayList(new Command(p1, 20));
    
    TableView<Command> tv = new TableView<Command>();
    tv.setItems(commands);
    
    /**
     * Substitua as sugestões de tipo Product por String da TableColumn e suas correlacionadas como abaixo
     */
    TableColumn<Command, String> tc = new TableColumn<Command, String>("Product");
    tc.setMinWidth(140);
    tc.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<Command, String>, ObservableValue<String>>(){
        @Override
        public ObservableValue<String> call(CellDataFeatures<Command, String> p) {
            return new SimpleObjectProperty(p.getValue().getProduct().getName());
        }
    });
    tc.setCellFactory(new Callback<TableColumn<Command, String>, TableCell<Command, String>>() {
        @Override
        public TableCell<Command, String> call(TableColumn<Command, String> p) {
            /**
             * Este Map guardará os objetos Product indexando pelo "name"
             */
            final Map<String, Product> products = new HashMap();
            Iterator<Product> productsi = pojosComboBox.iterator();
            while(productsi.hasNext()) {
                Product product = productsi.next();
                products.put(product.getName(), product);
            }
    
            ComboBoxTableCell cell = new ComboBoxTableCell(FXCollections.observableArrayList(products.keySet())){
                @Override
                public void updateItem(Object item, boolean empty) {
                    super.updateItem(item, empty);
                    if(item != null) {
                        /**
                         * Aqui acontece a atualização do objeto Command de acordo com o esperado
                         */
                        tabela.getItems().get(getIndex()).setProduct(products.get(item.toString()));
                    }
                }
            };
            cell.setAlignment(Pos.CENTER);
            return cell;
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try use string as a regular expression pattern but I've following errors PHP
I try to use a variable in my kshell script but can't get a
i try to use jquery .text() but not really work : Before <a id=group_name
I try to use this: xml2struct when I use this xml: <XMLname attrib1=Some value>
I try to use the columnFilter add-on of jquery datatable but I couldn't make
RegexBuddy shows the matches are OK, but in C# when I try use replace,
I try use ms access as data provider but it give me exception. static
I try use gssapi32.dll in my application but I receive exception when app start
how to generate random number in this code? I try use $RANDOM, but the
I try use webclient to translate word 'Banana' into rus private void button1_Click(object sender,

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.