JavaFx Set Tableview Cell Background Color Dynamically

gursahib.singh.sahni

I want to add color to the color cell of the rows dynamically when ADD button is clicked. I am not able to change the background color of the cell. Please see the image for reference. Am not able to achieve that with the help of code. Thanks for help in advance.

Snippet adding values to table :

     @FXML
     private void addEntity() {

      data.add(new Inventory(codeTemp.getText(), articleNameTemp.getText(), Integer.parseInt(amountTemp.getText()), dcTemp.isSelected() ? true:false, stTemp.isSelected()?true:false, Utilities.toRGBCode(colorTemp.getValue()), informationTemp.getText(), data.size()+1));
      inventoryTable.setItems(data);

     }

enter image description here

gursahib.singh.sahni

Did with the help of a callback on the column.

        Callback<TableColumn<Inventory, String>, TableCell<Inventory, String>> cellFactory =
        new Callback<TableColumn<Inventory, String>, TableCell<Inventory, String>>() {
            public TableCell call(TableColumn p) {
                TableCell cell = new TableCell<Person, String>() {
                    @Override
                    public void updateItem(String item, boolean empty) {
                        super.updateItem(item, empty);
                        setText(empty ? null : getString());
                        setStyle("-fx-background-color:"+getString());
                    }

                    private String getString() {
                        return getItem() == null ? "" : getItem().toString();
                    }
                };


                return cell;
            }
        };

enter image description here

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

JavaFX TableView custom cell color glitches when deleting item

JAVAFX: How to set a MouseEvent leftclick action on a cell with data in TableView

ComboBox in a tableview cell in JavaFX

set background color for specific cell in markdown table

How to Set the Background Color of a Cell in a MigraDoc Table

How to set row foreground color of a tableView on JavaFX?

TableView cell background color not changed when long pressed cell

How to set cell color in TableLayoutPanel dynamically?

How to set background color to a dynamically created view?

Excel: Set background color of cell and text color with rgb

How to set background color for a div dynamically in angular?

swift-Tableview cell UIButton background color

PhpSpreadsheet set background color of cell to white

Set background color in table cell

How to dynamically set the background color in an ASCX file?

Dynamically set the color collectionview label background color

How to dynamically set background color in IOS?

SSRS Dynamically change the cell background and font color

Set background color for a cell specified in JTable

Changing background color of each cell dynamically depending on its value

Set background for just one cell in a dynamic TableView

Set background cell color on CListCtrl

JavaFX Set Cell Background Color of TableColumn

JavaFX: is it possible to set a background color for an entire TreeView?

JavaFX: Set Background Color in TextFlow

How to set color to each row in javafx TableView individually?

How to set background color based on cell position?

TableView Cell skips with the color

Same RGB but different color for cell, header background in TableView

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  3. 3

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  4. 4

    pump.io port in URL

  5. 5

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  8. 8

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

  9. 9

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  10. 10

    How to remove the extra space from right in a webview?

  11. 11

    java.lang.NullPointerException: Cannot read the array length because "<local3>" is null

  12. 12

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  13. 13

    flutter: dropdown item programmatically unselect problem

  14. 14

    How to use merge windows unallocated space into Ubuntu using GParted?

  15. 15

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  16. 16

    Nuget add packages gives access denied errors

  17. 17

    Svchost high CPU from Microsoft.BingWeather app errors

  18. 18

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  19. 19

    12.04.3--- Dconf Editor won't show com>canonical>unity option

  20. 20

    Any way to remove trailing whitespace *FOR EDITED* lines in Eclipse [for Java]?

  21. 21

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

HotTag

Archive