0

I´m trying to add a color when the program starts. But I only want to add it in the first two rows and in a specific colum this is my code of the initialize

public void initialize(URL location, ResourceBundle resources) {
    for (int i=0;i<28;i++){
        if (i == 0 || i == 1){
            listaPaginacion.add(new tablaPaginacion(i,"S.O.",0,"100","Ocupado"));
            tvTablaPaginacion.setItems(listaPaginacion);
            tcId.setCellValueFactory(new PropertyValueFactory<>("Id"));
            tcPagina.setCellValueFactory(new PropertyValueFactory<>("Pagina"));
            tcTam.setCellValueFactory(new PropertyValueFactory<>("Tam"));
            tcTam.getStyleClass().add(i,"so-colum");

            tcEstado.setCellValueFactory(new PropertyValueFactory<>("Estado"));
            tcNumeroMarco.setCellValueFactory(new PropertyValueFactory<>("NumeroMarco"));

        }else{
            listaPaginacion.add(new tablaPaginacion(i,"",0,"0","Libre"));
            tvTablaPaginacion.setItems(listaPaginacion);
            tcId.setCellValueFactory(new PropertyValueFactory<>("Id"));
            tcPagina.setCellValueFactory(new PropertyValueFactory<>("Pagina"));
            tcTam.setCellValueFactory(new PropertyValueFactory<>("Tam"));
            tcTam.getStyleClass().remove("so-colum");
            tcEstado.setCellValueFactory(new PropertyValueFactory<>("Estado"));
            tcNumeroMarco.setCellValueFactory(new PropertyValueFactory<>("NumeroMarco"));

        }


    }
}

I tried to first add the class and then remove it but it doesn't work

  • Potential duplicate: [Background with 2 colors in JavaFX?](http://stackoverflow.com/questions/16200901/background-with-2-colors-in-javafx) You need to set the styles in the cell factory. You don't need a loop like you have in your question. The loop is just setting the same properties to the same values over and over again (except sometimes it overwrites existing values), so its useless. Make sure your table is actually displaying the correct values before you try to add custom styling to it. – jewelsea Apr 04 '17 at 22:46
  • The loop is for set the values when the program starts, it only make 28 rows and that is all, And i put the css beacuse when starts the programa the first two rows on one colum need to be on black but ill check the other post, thanks – Oscar.Aldaz Apr 05 '17 at 02:07

0 Answers0