Css 以tableview为中心的行与其他行有何不同?

Css 以tableview为中心的行与其他行有何不同?,css,javafx,styles,javafx-8,Css,Javafx,Styles,Javafx 8,我在JavaFX中有一个tableview,我不希望焦点行与其他行不同。问题是,当我单击一行并选择它时,该行的底部边框会消失。是哪个css属性造成的,我如何修复它 在附加的屏幕截图中,选择了所有行,我最后一次单击的是“nature”行 MCVE: Main.java: import javafx.application.Application; import javafx.beans.property.SimpleStringProperty; import javafx.collectio

我在JavaFX中有一个tableview,我不希望焦点行与其他行不同。问题是,当我单击一行并选择它时,该行的底部边框会消失。是哪个css属性造成的,我如何修复它

在附加的屏幕截图中,选择了所有行,我最后一次单击的是“nature”行

MCVE:

Main.java:

import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.control.SelectionMode;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableRow;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {

        HBox hBox = new HBox();
        Scene scene = new Scene(hBox, 300, 275);
        scene.getStylesheets().add("main.css");

        TableView<Keyword> keywordsTable = new TableView<>();
        TableColumn<Keyword, String> wordColumn = new TableColumn<>();
        ObservableList<Keyword> data = FXCollections.observableArrayList();

        wordColumn.setCellValueFactory(new PropertyValueFactory<>("word"));
        keywordsTable.getColumns().add(wordColumn);
        keywordsTable.setItems(data);

        keywordsTable.setRowFactory(param -> {
            TableRow<Keyword> row = new TableRow<>();
            row.addEventFilter(MouseEvent.MOUSE_CLICKED, e -> {
                keywordsTable.requestFocus();
                if (!row.isEmpty() && e.getButton().equals(MouseButton.PRIMARY)) {
                    changeRowSelection(keywordsTable, row.getItem(), row.getIndex());
                }
                e.consume();
            });

            row.addEventFilter(MouseEvent.MOUSE_PRESSED, e -> {
                keywordsTable.requestFocus();
                e.consume();
            });
            return row;
        });

        keywordsTable.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);

        data.add(new Keyword("one"));
        data.add(new Keyword("two"));
        data.add(new Keyword("three"));
        data.add(new Keyword("four"));
        data.add(new Keyword("five"));

        hBox.getChildren().add(keywordsTable);
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    private void changeRowSelection(TableView table, Keyword keyword, int index) {
        if (table.getSelectionModel().getSelectedItems().contains(keyword)) {
            table.getSelectionModel().clearSelection(index);
        } else {
            table.getSelectionModel().select(index);
        }
    }


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

    public class Keyword {

        private final SimpleStringProperty word;

        public Keyword(String word) {
            this.word = new SimpleStringProperty(word);
        }

        public String getWord() {
            return word.get();
        }

        public void setWord(String word) {
            this.word.set(word);
        }

    }
}

它为我提供了以下css

有关信息,请参阅:


请注意
.table view
中的自定义css变量定义。这不是强制性的,只是为了方便。

请使用定制的css发布。@UlukBiy,谢谢你的提示,我提供了MCVEyes,快速查看一下就知道它是有效的。你能分享一些描述-fx背景插入属性的文章吗?这有点让人困惑……当然可以@kapahgaii,又名“Karandash”。看见因为在上面的代码中,-fx背景色有2个值,用逗号分隔,-fx背景插入也有2个值。
.table-row-cell:focused {
    -fx-background-insets: 0;
    -fx-padding: 0;
}

.list-cell:filled:selected,
.tree-cell:filled:selected,
.table-row-cell:filled:selected,
.tree-table-row-cell:filled:selected,
.table-row-cell:filled > .table-cell:selected,
.tree-table-row-cell:filled > .tree-table-cell:selected {
    -fx-background: #C7E8EA;
    -fx-table-cell-border-color: #26ABD7 !important;
    -fx-text-fill: black;
}

.table-row-cell:focused {
    -fx-background-insets: 0 0 0;
}

.table-cell {
    -fx-background-insets: 0 !important; 
}
.table-view {
  -my-bg-color: #C7E8EA;
  -my-bd-color: violet;
}

.table-row-cell {
  -fx-background: -my-bg-color;
  -fx-background-color: -my-bd-color, -fx-background;
  -fx-background-insets: 0, 0 0 1 0;
  -fx-padding: 0;
  -fx-text-fill: black;
}

.table-cell {
  -fx-padding: 0.166667em; /* 2px, plus border adds 1px */
  -fx-background-color: null;
  -fx-border-color: transparent -my-bd-color transparent transparent;
  -fx-cell-size: 2.0em; /* 24 */
  -fx-text-fill: -fx-text-background-color;
}