I'd like to know, if it is possible to render simple HTML tags in JavaFX TableView (b, i, subscript, supscript). In my code snippet I used default cellValueFactory, but maybe someone could tell me if exists any cell factory which allow me to display html.
From code:
class Data{
private String row = " Sample data"
public String getRow(){
return row;
}
TableView tableView = new TableView();
TableColumn column = new TableColumn("Sample Column");
column.setCellValueFactory(new PropertyValueFactory("row"));
tableView.getColumns().addAll(column);
I wish I could see Sample Data in my table in bold. Thanks in advance!
--UPDATE
Code that allows me to see my HTML, but resizes table cell, WebView size is ignored and not wrapped tight
private class HTMLCell extends TableCell {
@Override
protected void updateItem(Component item, boolean empty) {
super.updateItem(item, empty);
if (!empty) {
WebView webView = new WebView();
webView.setMaxWidth(200);
webView.setMaxHeight(50);
WebEngine engine = webView.getEngine();
// setGraphic(new Label("Test"));
setGraphic(webView);
String formula = item.getFormula();
engine.loadContent(formula);
}
}
}
TableColumn formulaColumn = new TableColumn<>("Formula");
formulaColumn.setMinWidth(300);
formulaColumn.setCellFactory(new Callback, TableCell>() {
@Override
public TableCell call(TableColumn param) {
return new HTMLCell();
}
});
formulaColumn.setCellValueFactory(new Callback, ObservableValue>() {
@Override
public ObservableValue call(CellDataFeatures param) {
return new SimpleObjectProperty(param.getValue());
}
});