java 更改 JavaFX TableView 字体大小
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39512621/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change JavaFX TableView font size
提问by Krzysztof Pokrywka
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.
嗨,我想在 tablewView 的列中的文本上设置字体。我如何在 Java 中做到这一点,这是我的代码。感谢帮助。
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(
""));
回答by GOXR3PLUS
How to use the code below?
You can add it into an
external.css
file and then connect it to your app simple like this:
如何使用下面的代码?
您可以将它添加到一个
external.css
文件中,然后像这样简单地将它连接到您的应用程序:
1)What is wrong with my syntax calling a stylesheet (css) from an FXML file?2)https://blog.idrsolutions.com/2014/04/use-external-css-files-javafx/
1)我从 FXML 文件调用样式表 (css) 的语法有什么问题?2) https://blog.idrsolutions.com/2014/04/use-external-css-files-javafx/
Below is some css code that can be used to modify the table look.Note that a lot more exist,for that you can check modena.css.
下面是一些可用于修改表格外观的 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;
}