Java Code Examples for javafx.scene.control.TableView#setFixedCellSize()

The following examples show how to use javafx.scene.control.TableView#setFixedCellSize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ControlUtil.java    From pmd-designer with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Make a list view fit precisely the height of its items.
 *
 * @param view            The listview to configure
 * @param fixedCellHeight The cell height to use, a good default is 24
 */
public static void makeTableViewFitToChildren(TableView<?> view, double fixedCellHeight) {
    view.setFixedCellSize(fixedCellHeight);

    subscribeOnSkin(view, skin -> {

        Region header = (Region) skin.getNode().lookup(".nested-column-header");

        view.maxHeightProperty().bind(
            Val.wrap(view.itemsProperty())
               .flatMap(LiveList::sizeOf).map(it -> header.prefHeight(-1) + (it == 0 ? fixedCellHeight
                                                                                     : it * fixedCellHeight + 5))
        );

        return view.maxHeightProperty()::unbind;
    });

}
 
Example 2
Source File: FeatureTable.java    From sis with Apache License 2.0 4 votes vote down vote up
public FeatureTable(Resource res, int i) throws DataStoreException {
    TableView<AbstractFeature> ttv = new TableView<>();
    final ScrollPane scroll = new ScrollPane(ttv);
    scroll.setFitToHeight(true);
    scroll.setFitToWidth(true);
    ttv.setColumnResizePolicy(TableView.UNCONSTRAINED_RESIZE_POLICY);
    ttv.setTableMenuButtonVisible(true);
    ttv.setFixedCellSize(100);
    scroll.setPrefSize(600, 400);
    scroll.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
    setCenter(scroll);
    final List<AbstractFeature> list;
    if (res instanceof FeatureSet) {
        try (Stream<AbstractFeature> stream = ((FeatureSet) res).features(false)) {
            list = stream.collect(Collectors.toList());
            ttv.setItems(FXCollections.observableArrayList(list));
            for (AbstractIdentifiedType pt : list.get(0).getType().getProperties(false)) {
                final TableColumn<AbstractFeature, BorderPane> column = new TableColumn<>(generateFinalColumnName(pt));
                column.setCellValueFactory((TableColumn.CellDataFeatures<AbstractFeature, BorderPane> param) -> {
                    final Object val = param.getValue().getPropertyValue(pt.getName().toString());
                    if (val instanceof Geometry) {
                        return new SimpleObjectProperty<>(new BorderPane(new Label("{geometry}")));
                    } else {
                        SimpleObjectProperty<BorderPane> sop = new SimpleObjectProperty<>();
                        if (val instanceof CheckedArrayList<?>) {
                            Iterator<String> it = ((CheckedArrayList<String>) val).iterator();
                            TreeItem<String> ti = new TreeItem<>(it.next());
                            while (it.hasNext()) {
                                ti.getChildren().add(new TreeItem<>(it.next()));
                            }
                            BorderPane bp = new BorderPane(new TreeView<>(ti));
                            sop.setValue(bp);
                            return sop;
                        } else {
                            sop.setValue(new BorderPane(new Label(String.valueOf(val))));
                            return sop;
                        }
                    }
                });
                ttv.getColumns().add(column);
            }
        }
    }
}