2014-03-26 37 views
1

根據this very similar question,應該使用高特異性或!important標記來更改非常'隱藏'的選擇器。TableView -fx-text-fill on rows

但是,我似乎無法更改TableRow-fx-text-fill

我寧願解決這個問題,而不是在排廠使用setTextFill


SSCCE

tableviewtester.css去旁邊TableViewTester類,幷包含:

.myrow { 
    -fx-selection-bar-text: red; 
    -fx-text-fill: red; 
} 

通知的-fx-selection-bar-text工作。

import javafx.application.Application; 
import javafx.beans.property.SimpleStringProperty; 
import javafx.beans.value.ObservableValue; 
import javafx.collections.FXCollections; 
import javafx.scene.Scene; 
import javafx.scene.control.TableColumn; 
import javafx.scene.control.TableColumn.CellDataFeatures; 
import javafx.scene.control.TableRow; 
import javafx.scene.control.TableView; 
import javafx.scene.layout.StackPane; 
import javafx.stage.Stage; 
import javafx.util.Callback; 

/** 
* 
* @author ggrec 
* 
*/ 
public class TableViewTester extends Application 
{ 

    // ==================== 3. Static Methods ==================== 

    public static void main(final String[] args) 
    { 
     launch(args); 
    } 


    // ==================== 4. Constructors ==================== 

    @Override 
    public void start(final Stage primaryStage) throws Exception 
    { 
     final Scene scene = new Scene(createContents()); 
     scene.getStylesheets().add(this.getClass().getResource("tableviewtester.css").toExternalForm()); 

     primaryStage.setScene(scene); 
     primaryStage.show(); 
    } 


    // ==================== 5. Creators ==================== 

    private StackPane createContents() 
    { 
     final StackPane pane = new StackPane(); 

     final TableView<String> table = new TableView<>(); 
     table.setRowFactory(new TableRowFactory()); 

     final TableColumn<String, String> column = new TableColumn<>("Color"); 
     column.setCellValueFactory(new TableCellValueFactory()); 
     column.prefWidthProperty().setValue(300); 

     // Add Columns 
     table.getColumns().setAll(FXCollections.observableArrayList(column)); 

     // Add Items 
     table.setItems(FXCollections.observableArrayList("Green", "Red", "Blue")); 

     pane.getChildren().setAll(table); 

     return pane; 
    } 


    // ======================================================= 
    //   19. Inline Classes 
    // ======================================================= 

    private class TableCellValueFactory implements Callback<CellDataFeatures<String, String>, ObservableValue<String>> 
    { 
     @Override 
     public ObservableValue<String> call(final CellDataFeatures<String, String> cellWrapper) 
     { 
      return new SimpleStringProperty(cellWrapper.getValue()); 
     } 
    } 

    private class TableRowFactory implements Callback<TableView<String>, TableRow<String>> 
    { 
     @Override 
     public TableRow<String> call(final TableView<String> arg0) 
     { 
      final TableRow<String> row = new TableRow<String>() { 

       @Override protected void updateItem(final String line, final boolean empty) 
       { 
        super.updateItem(line, empty); 

        this.getStyleClass().add("myrow"); 
       } 
      }; 

      return row; 
     } 
    } 

} 

回答