Java FX: TableView - Displays plain HTML

I would like to know if simple HTML tags can be rendered in JavaFX TableView (b, i, subscript, supscript). In my code snippet, I used default cellValueFactory, but maybe someone could tell me if there is any factory cell that allows me to display html.

From the code:

class Data{
    private String row = "<b> Sample data</b>"

    public String getRow(){
        return row;
}

TableView<Data> tableView = new TableView();
TableColumn<Data,String> column = new TableColumn("Sample Column");
column.setCellValueFactory(new PropertyValueFactory<Data, String>("row"));
tableView.getColumns().addAll(column);

I wish I could see examples of data in my table in bold. Thanks in advance!

- ADDED Code that allows me to see my HTML, but it resizes the table cell, the size of the WebView is ignored and not delayed.

 private class HTMLCell extends TableCell<Component, Component> {

  @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<Component, Component> formulaColumn = new TableColumn<>("Formula");
  formulaColumn.setMinWidth(300);
  formulaColumn.setCellFactory(new Callback<TableColumn<Component, Component>, TableCell<Component, Component>>() {

   @Override
   public TableCell<Component, Component> call(TableColumn<Component, Component> param) {
    return new HTMLCell();
   }
  });

  formulaColumn.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<Component, Component>, ObservableValue<Component>>() {

   @Override
   public ObservableValue<Component> call(CellDataFeatures<Component, Component> param) {
    return new SimpleObjectProperty<Component>(param.getValue());
   }
  });
+3
source share
2 answers

HTML in WebView in TableCell

factory, WebView node, HTML-.

WebView

WebView node, . , RT-25005 WebView.

, , maxSize WebView webView.setPrefSize(prefX, prefY). , prefX prefY , , .

, , WebView, WebView, , pref, , , ​​Java 8b129 ( JavaFX Issue Tracker , ).

TextFlow

TextFlow . HTML, , , , , , .

+2

HTML- WebEngine/WebView, TableView.

+1

Source: https://habr.com/ru/post/1015831/


All Articles