java - TableView -fx-text-fill 行

标签 java javafx javafx-2 javafx-8

根据this very similar question ,应该使用高特异性或 !important 标签来更改非常“隐藏”的选择器。

但是,我似乎无法更改 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;
        }
    }

}

最佳答案

-fx-text-inner-color 是正确的属性,而不是 -fx-fill-color

<小时/>

Reference #1

Reference #2

Reference #3

Reference #4

关于java - TableView -fx-text-fill 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22663269/

相关文章:

java - 注释android后的MuPdf保存文件

java - 从多个线程读取相同的 ResultSet

Java 从 UserList 和 setItems ComboBox 获取用户名

java - 如何使用 gradle-launch4j 插件将 gradle 项目编译为 exe

c# - 具有属性和方法的内存类生成

java - ActionListener 是 java 中的线程吗?

java - 在JavaFX中静音一个WebView,有可能吗?

java - 文本字段 requestFocus 失去第一次按键? (JavaFX2)

java - 为什么我的 JavaFX 2 应用程序的可见帧速率如此不可靠?

javafx - 如何获取 TableView 中 ComboBoxTableCell 中选定的值