Javafx:设置TreeTableView的背景

时间:2015-06-17 10:36:47

标签: java css javafx

我正在尝试设置TreeTableView

的背景

使用的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");
}

enter image description here 这是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 ;
    });

我得到了这个css:

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

enter image description here

2 个答案:

答案 0 :(得分:0)

不透明度可以帮助您使其透明,以显示其背后的父母。

内联CSS:

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

单独的CSS文件:

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

在上面的代码中,0.5指定节点的不透明度或alpha属性。值为0.5使其半透明。因此,a的值范围为0到1,其中1表示完全可见,0表示完全不透明。

答案 1 :(得分:0)

试试这个css样式:

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

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

经过测试:

@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();
}