gpt4 book ai didi

java - TableView -fx-text-fill 行

转载 作者:太空宇宙 更新时间:2023-11-04 06:56:34 25 4
gpt4 key购买 nike

根据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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com