简体   繁体   English

JavaFX:设置TreeTableView的背景

[英]Javafx: set the background of a TreeTableView

I'm trying to set the background of a TreeTableView . 我正在尝试设置TreeTableView的背景。

CSS Styling Used : CSS样式使用:

.tree-table-cell, cell{
   -fx-background-color: rgba(0, 0, 0, 1);
   -fx-background-image: url("blur03.jpg");
}

.tree-table-row-cell{
   -fx-background-image: url("blur03.jpg");
}

在此处输入图片说明 here is an implementation of a TreeTableColumn in the treetableview 这是treetableview中TreeTableColumn的实现

final TreeTableColumn<RootMaster, Integer> dataColumn = new TreeTableColumn<>("Data");
    dataColumn.setCellValueFactory(new TreeItemPropertyValueFactory<RootMaster, Integer>("budgetSum"));
    dataColumn.setCellFactory(col -> {
        TreeTableCell<RootMaster, Integer> cell = new TreeTableCell<RootMaster, Integer>() {
            @Override
            public void updateItem(Integer item, boolean empty) {
                super.updateItem(item, empty);
                if (empty) {
                    setText(null);
                } else {
                    setText(item.toString());
                }
            }
        };
        cell.setAlignment(Pos.CENTER);
        return cell ;
    });

with this css I get: 有了这个CSS我得到:

.tree-table-view, .table-view{
-fx-opacity: 0.3;}

在此处输入图片说明

Opacity can help you to make it a little transparent to show the parent behind it. 不透明度可以帮助您使其更加透明,以显示其背后的父母。

Inline CSS: 内联CSS:

tableView.setStyle(
"-fx-background-color: rgba(0, 100, 100, 0.5);
-fx-background-radius: 10;"
);

Seperate CSS file: 单独的CSS文件:

.tree-table-view, .table-view{
-fx-background-color: rgba(0, 100, 100, 0.5);
}

In the above code, 0.5 specifies the opacity or alpha property of the node. 在上面的代码中,0.5指定节点的不透明度或alpha属性。 A value of 0.5 makes it half opaque. 值0.5使其变为半透明。 Thus the value of a ranges from 0 to 1 where 1 is fully visible and 0 is fully opaque. 因此,a的值介于0到1之间,其中1完全可见,而0完全不透明。

Try this css styling: 尝试以下CSS样式:

.tree-table-row-cell {
    -fx-background: transparent;
}

.tree-table-view {
    -fx-background-color: transparent;
}

Tested with: 经过测试:

@Override
public void start( Stage stage )
{
    TreeItem<String> childNode1 = new TreeItem<>( "Node 1" );
    TreeItem<String> childNode2 = new TreeItem<>( "Node 2" );
    TreeItem<String> childNode3 = new TreeItem<>( "Node 3" );

    TreeItem<String> root = new TreeItem<>( "Root" );
    root.setExpanded( true );

    root.getChildren().setAll( childNode1, childNode2, childNode3 );

    TreeTableColumn<String, String> column = new TreeTableColumn<>( "Column" );
    column.setPrefWidth( 150 );

    column.setCellValueFactory( ( TreeTableColumn.CellDataFeatures<String, String> p ) 
            -> new ReadOnlyStringWrapper( p.getValue().getValue() ) );

    TreeTableView<String> treeTableView = new TreeTableView<>( root );
    treeTableView.getColumns().add( column );


    VBox box = new VBox( treeTableView, new Button( "test" ) );
    box.setStyle( "-fx-background-color: green" );

    final Scene scene = new Scene( box, 200, 400 );
    scene.getStylesheets().add( "path/to/the-style-above.css" );
    stage.setScene( scene );
    stage.show();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM