1

Samples オブジェクトが取り込まれたテーブル ビューがあります。Samples オブジェクトのプロパティ = true の場合、TableRow を埋めたいと思います。ジュエルシーのこの回答に基づく方法を使用しました:データに基づいてTableRowを無効にする

int i = 0;
if (tblSamples.getItems().size() > 0) {
    for (Node n : tblSamples.lookupAll("TableRow")) {
        if (n instanceof TableRow) {
            TableRow row = (TableRow) n;
            row.getStyleClass().removeAll("hasMastitisRow");

            if (tblSamples.getItems().get(i).getClinicalMastitis()) {
                row.getStyleClass().add("hasMastitisRow");
            }
            i++;

            if (i == tblSamples.getItems().size()) {
                break;
            }
        }
    }
}

CSS:

.hasMastitisRow {  
    -fx-control-inner-background: linear-gradient(#FFFFFF 85%, red 100%);
}

ただし、奇数行にのみ適用され、偶数行では機能しないようですか?

編集:CSSが偶数行に適用されると、次のエラーが発生するようです(奇数行ではエラーは発生しません):

WARNING: com.sun.javafx.css.StyleHelper calculateValue Could not resolve '-fx-table-cell-border-color' while resolving lookups for '-fx-background-color' from rule '*.table-row-cell:odd' in stylesheet jar:file:/C:/Program%20Files/Java/jdk1.7.0_15/jre/lib/jfxrt.jar!/com/sun/javafx/scene/control/skin/caspian/caspian.bss
WARNING: com.sun.javafx.css.StyleHelper calculateValue Could not resolve '-fx-control-inner-background' while resolving lookups for '-fx-text-fill' from rule '*.table-cell' in stylesheet jar:file:/C:/Program%20Files/Java/jdk1.7.0_15/jre/lib/jfxrt.jar!/com/sun/javafx/scene/control/skin/caspian/caspian.bss
WARNING: com.sun.javafx.css.StyleHelper calculateValue Could not resolve '-fx-control-inner-background' while resolving lookups for '-fx-text-fill' from rule '*.table-cell' in stylesheet jar:file:/C:/Program%20Files/Java/jdk1.7.0_15/jre/lib/jfxrt.jar!/com/sun/javafx/scene/control/skin/caspian/caspian.bss
WARNING: com.sun.javafx.css.StyleHelper calculateValue Could not resolve '-fx-control-inner-background' while resolving lookups for '-fx-text-fill' from rule '*.table-cell' in stylesheet jar:file:/C:/Program%20Files/Java/jdk1.7.0_15/jre/lib/jfxrt.jar!/com/sun/javafx/scene/control/skin/caspian/caspian.bss
WARNING: com.sun.javafx.css.StyleHelper calculateValue Could not resolve '-fx-control-inner-background' while resolving lookups for '-fx-text-fill' from rule '*.table-row-cell' in stylesheet jar:file:/C:/Program%20Files/Java/jdk1.7.0_15/jre/lib/jfxrt.jar!/com/sun/javafx/scene/control/skin/caspian/caspian.bss
WARNING: com.sun.javafx.css.StyleHelper calculateValue Could not resolve '-fx-table-cell-border-color' while resolving lookups for '-fx-background-color' from rule '*.table-row-cell:odd' in stylesheet jar:file:/C:/Program%20Files/Java/jdk1.7.0_15/jre/lib/jfxrt.jar!/com/sun/javafx/scene/control/skin/caspian/caspian.bss
WARNING: com.sun.javafx.css.StyleHelper calculateValue Could not resolve '-fx-control-inner-background' while resolving lookups for '-fx-text-fill' from rule '*.table-cell' in stylesheet jar:file:/C:/Program%20Files/Java/jdk1.7.0_15/jre/lib/jfxrt.jar!/com/sun/javafx/scene/control/skin/caspian/caspian.bss
WARNING: com.sun.javafx.css.StyleHelper calculateValue Could not resolve '-fx-control-inner-background' while resolving lookups for '-fx-text-fill' from rule '*.table-cell' in stylesheet jar:file:/C:/Program%20Files/Java/jdk1.7.0_15/jre/lib/jfxrt.jar!/com/sun/javafx/scene/control/skin/caspian/caspian.bss
WARNING: com.sun.javafx.css.StyleHelper calculateValue Could not resolve '-fx-control-inner-background' while resolving lookups for '-fx-text-fill' from rule '*.table-cell' in stylesheet jar:file:/C:/Program%20Files/Java/jdk1.7.0_15/jre/lib/jfxrt.jar!/com/sun/javafx/scene/control/skin/caspian/caspian.bss

編集: 新しいアプローチですが、結果は同じです(偶数行ではなく、奇数行に適用されます):

tc_Samples_Quarter.setCellFactory(new Callback<TableColumn<Samples, String>, TableCell<Samples, String>>() {
        @Override
        public TableCell<Samples, String> call(TableColumn<Samples, String> soCalledSampleRowStringTableColumn) {
            return new TableCell<Samples, String>() {
                @Override
                public void updateItem(final String item, final boolean empty) {
                    super.updateItem(item, empty);
                    this.getTableRow().getStyleClass().remove("hasMastitisRow");
                    if (item != null) {
                        setText(item);
                        this.getTableRow().getStyleClass().add("hasMastitisRow");
                    } else {
                        setText(null);
                    }
                }
            };
        }
    });
4

2 に答える 2

0

あなたのコードのいくつかに興味があります。まず、次のようにノードをフェッチします。

for (Node n : tblSamples.lookupAll("TableRow")) {

次に、チェックのインスタンスを実行して、それが TableRow であるかどうかを確認します

if (n instanceof TableRow) {

それは必要ですか?lookupAllが TableRow 以外のノードを返す可能性はありますか? その場合、 iインデックスのインクリメントはif (n instanceof TableRow)内でのみ行われる可能性があるため、iはそれが TableRow の場合にのみインクリメントされます。ループに追いついていないため、インデックス内のアイテムと一致していない可能性がありますか?

于 2013-03-03T14:12:56.470 に答える
0

これは、setCellFactory ソリューション (上記の質問の他のアプローチを参照) を使用し、CSS を次のように調整することで修正されました。

.hasMastitisRow {  
    -fx-background-color: linear-gradient(#FFFFFF 85%, red 100%);
}
于 2013-04-10T17:40:37.957 に答える