2017-02-17 46 views
0

我改变我的一些表行的作风,以做一些高亮:更改排边框颜色引入了一些奇怪的细胞移

table.setRowFactory(tv -> new TableRow<TableBean>() { 

     @Override 
     public void updateItem(TableBean item, boolean empty) { 

     super.updateItem(item, empty); 
     if (item == null) { 
      setStyle(""); 
     } else if (item.getComparisonElement().isMarker()) { 
      setStyle("-fx-border-color: red;"); 
     } else { 
      setStyle(""); 
     } 
     } 
    }); 

这工作,但我有一些细胞“平移”为不良副作用:

enter image description here

回答

0

我怀疑有带有边框的某些行和其他人不被弄乱布局。

默认样式表modena.css实现大多数边框效果的方式实际上是使用“嵌套背景”。这个想法是绘制一个没有插图的纯色背景色,然后用正插图绘制第二个背景色。例如。如果您用零插图绘制红色背景,然后使用默认背景色以及每边1像素的插值绘制背景,则会创建1像素宽的红色边框的效果。 (有趣的是 - 我没有任何真实的证据 - 这种技术比使用实际的边框设置具有更好的性能。)这种用例的优点是添加(实际)边框会将表行的布局更改为空间分配给边界,而改变背景颜色对布局没有影响。

那么试试这个来代替:

table.setRowFactory(tv -> new TableRow<TableBean>() { 

    @Override 
    public void updateItem(TableBean item, boolean empty) { 

     super.updateItem(item, empty); 
     if (item == null) { 
      setStyle(""); 
     } else if (item.getComparisonElement().isMarker()) { 
      setStyle("-fx-background-color: red, -fx-background;"+ 
        "-fx-background-insets: 0, 1;"); 
     } else { 
      setStyle(""); 
     } 
    } 
}); 
+0

要命,就像一个魅力!你能解释一下如何解决这个问题,而不用触摸“无高亮”行吗? – kerner1000

+0

@ kerner1000添加了简要说明。 –