更改JavaFX TableView字体大小 [英] Change JavaFX TableView font size

查看:491
本文介绍了更改JavaFX TableView字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在tablewView的列内的文本上设置字体.我如何在Java中做到这一点,这就是我的代码.感谢您的帮助.

Hi I want to set Font on text inside in column in tablewView. How I can do it in Java this is my code. Thanks for help.

    private final TableView<AnotherBus> table = new TableView<>();

    TableColumn busNumberCol = new TableColumn("Linia");
            busNumberCol.setCellValueFactory(
                    new PropertyValueFactory<>("busNumber"));
            busNumberCol.getStyleClass().add("Times New Roman,40");

            tb.getStyleClass().add("Times New Roman");

            TableColumn courseCol = new TableColumn("Kierunek");
            courseCol.setCellValueFactory(
                    new PropertyValueFactory<>("nameBusStpo"));
            courseCol.setPrefWidth(200);
            courseCol.getStyleClass().add("Times New Roman");
            TableColumn departureCol = new TableColumn("Odjazd");
            departureCol.setCellValueFactory(
                    new PropertyValueFactory<>("busTimetable"));
            table.setItems(list);
            table.getColumns().addAll(busNumberCol, courseCol, departureCol);
            table.setPlaceholder(new Label(

""));

推荐答案

如何使用下面的代码❓

How to use the code below❓

您可以将其添加到external.css文件中,然后像下面这样简单地将其连接到您的应用程序:

You can add it into an external.css file and then connect it to your app simple like this:

1) https://blog.idrsolutions.com/2014/04/use-external-css-files-javafx/

下面是一些可用于修改表外观的css代码.请注意,还存在许多其他代码,您可以检查 modena.css .

//Style of entire tableView
.table-view{
    /*-fx-background-color: transparent;*/
 }

 //Style of entire tableView when is getting focused
.table-view:focused{
    /*-fx-background-color: transparent;*/
}



//Style of each column header in the tableView
.table-view .column-header {
     -fx-background-color: transparent;
} 

//Style of each column header's background in the tableView
.table-view .column-header-background{
    -fx-background-color: linear-gradient(#131313 0.0%, #424141 100.0%);
}

 //Style of each column header's label  in the tableView
.table-view .column-header-background .label{
     -fx-background-color: transparent; 
    -fx-font-weight:bold;
    -fx-text-fill: white;
}

//Style of each column in the tableView
.table-view .table-column{
    -fx-alignment:center;
}

 //Style of each table cell
.table-view .table-cell{
    -fx-font-weight:bold;
    -fx-font-size:15px;           //the font size you asked in the comments below
    /* -fx-text-fill:orange; */

}


//Style for each < non odd> row of table view
/* .table-row-cell{
    -fx-background-color: white;
    -fx-background-insets: 0.0, 0.0 0.0 1.0 0.0;
    -fx-padding: 0.0em; 
}

//Style for each <odd> row of table view
.table-row-cell:odd{
    -fx-background-color: orange;
    -fx-background-insets: 0.0, 0.0 0.0 1.0 0.0;
    -fx-padding: 0.0em;  
}
*/

//Style of each entire row in the table view
.table-row-cell:selected {
   /* -fx-border-color:transparent firebrick transparent firebrick  ;
    -fx-border-width:2.0; */
}


//Style of each entire row in the table view when is hovered
.table-row-cell:hover {
    -fx-background-color:orange;
}

//Style of each entire row in the table view when is getting focused
.table-row-cell:focused {
    -fx-background-color:purple;
}

这篇关于更改JavaFX TableView字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆