Show colors of an array in JavaFx

0

I have this little program in JavaFx that goes through the image and shows me all the colors it has, in the table next I show the color code, but I want to show the visible color and not the code and I wanted to know how I could fill each cell of the color corresponding to the code it has there.

    
asked by Jeisson Hernandez 02.12.2017 в 03:37
source

1 answer

1

Here is an example code, you can modify the data of interest but remember that it is the same structure and you can apply it to any column.

public void modificarCelda(TableColumn<Modelo_Mensual, String> cedulas){ // columna de interes
    cedulas.setCellFactory(new Callback<TableColumn<Modelo_Mensual, String>, TableCell<Modelo_Mensual, String>>(){ // cambiar el factor o como se va a comportar la celda
        @Override
        public TableCell<Modelo_Mensual, String> call(TableColumn<Modelo_Mensual, String> param) {

            return new TableCell<Modelo_Mensual, String>(){
                @Override
                protected void updateItem(String item, boolean empty) {//actualizando la celda con los parametros de interes
                    super.updateItem(item, empty); //To change body of generated methods, choose Tools | Templates.

                  if (item != null){ //esta es para asegurarse que haya informacion
                        setStyle("-fx-background-color:#"+item); //y se coloca el estilo de fondo segun el color que mencione la celda
                        //-fx-background-color:#f0f8ff //este es un ejemplo de como debe quedar.
                 }

                }
            };
        }
    });
}
    
answered by 03.12.2017 / 16:23
source