2014-09-05 63 views

回答

1

使用自定义电池工厂的样式类添加到单元格:

firstNameCol.setCellFactory(col -> { 
     TableCell<Person, String> cell = new TableCell<Person, String>() { 
      @Override 
      public void updateItem(String name, boolean empty) { 
       super.updateItem(name, empty); 
       if (empty) { 
        setText(""); 
       } else { 
        setText(name); 
       } 
      } 
     }; 
     cell.getStyleClass().add("no-select-cell"); 
     return cell ; 
    }); 

,然后在外部样式表,恢复为no-select-cell风格在选择的行为默认值:

.table-row-cell:selected .no-select-cell { 

    -fx-background: -fx-control-inner-background; 
    -fx-background-color: -fx-background; 
    -fx-text-fill: -fx-text-background-color; 
} 

.table-row-cell:odd:selected .no-select-cell { 
    -fx-background: -fx-control-inner-background-alt ; 
} 
相关问题