【发布时间】:2018-06-22 01:11:56
【问题描述】:
我正在使用 Vaadin,我想为我的网格/表格中的特定单元格设置背景颜色,或者如果无法为特定单元格设置背景颜色,我想至少为特定单元格设置字体颜色网格/表格。我有一个网格/表格的代码 TableView 如下:
package com.trading.scraper;
import com.vaadin.navigator.View;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.Grid;
import com.vaadin.ui.VerticalLayout;
import java.util.Arrays;
import java.util.List;
class TableView extends CustomComponent implements View {
static final String NAME = "Stock table";
TableView() {
final VerticalLayout layout = new VerticalLayout();
List<Stock> people = Arrays.asList(
new Stock("1", "2", "1"),
new Stock("3", "5", "2"),
new Stock("1", "3", "4"));
Grid<Stock> grid = new Grid<>();
grid.setWidth(100, Unit.PERCENTAGE);
grid.setItems(people);
grid.addColumn(Stock::getValue1).setCaption("Value1");
grid.addColumn(Stock::getValue2).setCaption("Value2");
grid.addColumn(Stock::getValue3).setCaption("Value3");
layout.addComponents(grid);
setCompositionRoot(layout);
}
}
网格/表格的内容类是:
package com.trading.scraper;
public class Stock {
private String value1;
private String value2;
private String value3;
public String getValue1() {
return value1;
}
public void setValue1(String value1) {
this.value1 = value1;
}
public String getValue2() {
return value2;
}
public void setValue2(String value2) {
this.value2 = value2;
}
public String getValue3() {
return value3;
}
public void setValue3(String value3) {
this.value3 = value3;
}
public Stock() {
}
Stock(String value1, String value2, String value3) {
this.value1 = value1;
this.value2 = value2;
this.value3 = value3;
}
}
如果可以为特定单元格设置背景颜色或至少设置字体颜色并且您知道该怎么做,请写信。例如。其中网格/表格中单元格的值为“1”我想将其设为红色,但如果例如单元格的值为“5”我想将其设为绿色,如果单元格的值为“3”我想将其设为黄色。非常感谢。
【问题讨论】: