2016-09-15 8 views
3

Hallo ich möchte Schriftart auf Text innerhalb Spalte in TablewView festlegen. Wie ich es in Java machen kann ist das mein Code. Danke für die Hilfe.JavaFX TableView Schriftgröße ändern

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(

"")); 
+1

Sie möchten die Farbe der Zelle oder die Farbe der Spaltenüberschrift ändern? – GOXR3PLUS

+0

@ GoXR3Plus Ich möchte, dass der Text größer wird –

Antwort

3

Wie Sie den Code verwenden below❓

Sie es in eine external.css Datei hinzufügen können, und schließen Sie es dann auf Ihre App einfach wie folgt aus:

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/

Unten ist einige CSS-Code, mit dem das Aussehen der Tabelle geändert werden kann. Beachten Sie, dass viel mehr existieren, dafür können Sie überprüfen, 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; 
}