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 - 如何正确使用@SuppressFBWarnings 忽略printStackTrace findbugs 警告

java - 如何从文本字段计算中获得答案

css - 在 JavaFX 中使用 CSS 旋转 3D

css - fxml 中的组合框菜单项字体更改

javafx-2 - javafx2 中的菜单项工具提示

java - 使用 javafx 将子窗口面板放入 Canvas 场景中

java - 运行 nokia 6212 模拟器时出现内部 RMI 注册表端口问题

java - 所需的 XMLGregorianCalendar 日期和时间,例如2012-06-08T08 :16:43+00:00 format (according to the W3C guidelines)

JavaFX:与文本具有相同宽度和大小的按钮

java - JBoss EAP 6.2 JMX 服务器和注册表绑定(bind)