title: JavaFX cells colors in TableView
body: <p>I want create TableView with multicolor cells. But i still need highlight cells in selected rows. How can i do that? For example i have class User - bean with FXproperties, and i need paint cells in column "Orders count", that contains "1". If row, containing such cell, is selected - this cell should be selected too.
  User class:</p>
  
  <pre><code>public class User {
  private StringProperty firstName = new SimpleStringProperty();
  private StringProperty lastName = new SimpleStringProperty();
  private IntegerProperty ordersCount = new SimpleIntegerProperty(0);
  
  public User(String firstName, String lastName, int ordersCount) {
      this.firstName.set(firstName);
      this.lastName.set(lastName);
      this.ordersCount.set(ordersCount);
  }
  
  public final String getFirstName() {
      return firstName.get();
  }
  
  public final String getLastName() {
      return lastName.get();
  }
  
  public Integer getOrdersCount() {
      return ordersCount.get();
  }
  
  public void setFirstName(String firstName) {
      this.firstName.set(firstName);
  }
  
  public void setLastName(String lastName) {
      this.lastName.set(lastName);
  }
  
  public void setOrdersCount(Integer ordersCount) {
      this.ordersCount.set(ordersCount);
  }
  
  public StringProperty firstNameProperty(){
      return firstName;
  }
  
  public StringProperty lastNameProperty(){
      return lastName;
  }
  
  public IntegerProperty ordersCountProperty(){
      return ordersCount;
  }
  </code></pre>
  
  <p>}    </p>
  
  <p>css file: </p>
  
  <pre><code>.oneCell  {  
   -fx-control-inner-background: lightsteelblue;
   -fx-background-color: -fx-table-cell-border-color, -fx-control-inner-background;
   -fx-background-insets: 0, 0 0 1 0;
  }
  </code></pre>
  
  <p>Main class:</p>
  
  <pre><code>public class JavaFXApplication13 extends Application {
  
  
  
  @Override
  public void start(Stage primaryStage) {
      ObservableList&lt;User&gt; users = FXCollections.observableArrayList();
      for(int i = 0; i &lt; 100; i++){
          users.add(Helper.createRandomUser());
      }        
      TableView&lt;User&gt; tableView = new TableView&lt;&gt;();
      tableView.setItems(users);
      TableColumn&lt;User, String&gt; firstNameColumn = new TableColumn&lt;&gt;("First name");
      firstNameColumn.setCellValueFactory(new PropertyValueFactory&lt;User, String&gt;("firstName"));
      TableColumn&lt;User, String&gt; lastNameColumn = new TableColumn&lt;&gt;("Last name");
      lastNameColumn.setCellValueFactory(new PropertyValueFactory&lt;User, String&gt;("lastName"));
      TableColumn&lt;User, Object&gt; ordersCountColumn = new TableColumn&lt;&gt;("Orders count");
      ordersCountColumn.setCellValueFactory(new PropertyValueFactory&lt;User, Object&gt;("ordersCount"));
      ordersCountColumn.setCellFactory(new CellFactory());
      tableView.getColumns().addAll(firstNameColumn, lastNameColumn, ordersCountColumn);
  
      StackPane root = new StackPane();
      root.getChildren().add(tableView);
      Scene scene = new Scene(root, 500, 500);
      scene.getStylesheets().add("javafxapplication13/main.css");
      primaryStage.setTitle("Hello World!");
      primaryStage.setScene(scene);
      primaryStage.show();
  }
  
  
  public static void main(String[] args) {
      launch(args);
  }
  
  
   private class CellFactory implements Callback&lt;TableColumn&lt;User, Object&gt;, TableCell&lt;User, Object&gt;&gt; {
  
      @Override
      public TableCell&lt;User, Object&gt; call(TableColumn&lt;User, Object&gt; p) {
         TableCell&lt;User, Object&gt; cell = new TableCell&lt;User, Object&gt;(){
            @Override
              public void updateItem(Object item, boolean empty) {
                  super.updateItem(item, empty);
                  String text = getString();
                  setText(empty ? null : text);
                  setGraphic(null);
                  getStyleClass().remove("oneCell");
                  if (text != null &amp;&amp; text.contains("1")) {
                      getStyleClass().add("oneCell");
                  }
              }
  
              private String getString() {
                  return getItem() == null ? "" : getItem().toString();
              }  
         };
         return cell;
      }
   }
  
  }
  </code></pre>