javafx - событие мыши табличного представления не перехвачено - PullRequest
0 голосов
/ 24 октября 2019

У меня есть TableView в моем fxml. Внутри контроллера эта таблица отображается с аннотацией @FXML.

@FXML
TableView<BankMovement> table;

Я также установил в документе fxml элемент таблицы

onMouseReleased = "#handleRowSelect"

, наконец, всегда в контроллере, который у меня естьследующий метод

@FXML
private void handleRowSelect(MouseEvent event){
    Document row = table.getSelectionModel().getSelectedItem();
    if (row == null) return;
    if(row != temp){
        temp = row;
        lastClickTime = new Date();
    } else if(row == temp) {
        Date now = new Date();
        long diff = now.getTime() - lastClickTime.getTime();
        if (diff < 300){ 
            System.out.println("Edit dialog");
            System.out.print(row.getDescription());
        } else {
            lastClickTime = new Date();
            System.out.print(row.getFile());

        }
    }
}

здесь вместо этого есть место для привязки данных к таблице

@Override
public void initializeTable() {
    table.setItems(subList());
    colId.setCellValueFactory(new PropertyValueFactory<>("idDocument"));
    colIdCategory.setCellValueFactory(d -> new SimpleStringProperty(d.getValue().getCategory().getName()));
    colIdCategoryChild.setCellValueFactory(d -> new SimpleStringProperty(d.getValue().getCategoryChild().getName()));
    colIdDocument.setCellFactory(getFileCellFactory());
    colIdDocument.setCellValueFactory(new PropertyValueFactory<>("file"));
    colIdDescription.setCellValueFactory(new PropertyValueFactory<>("description"));
    colIdDate.setCellValueFactory(d -> new SimpleStringProperty(Utils.localTimeToItalianDate(d.getValue().getDocumentDate())));
}

Даже если я нажму на таблицу, я никогда не введу метод handleRowSelect.

У меня сложилось впечатление, что когда я щелкаю по строке, щелчок по ячейке управляется, а не по строке. Как будто событие не было распространено.

Это fxml

<AnchorPane minWidth="-Infinity"  prefHeight="900.0" prefWidth="1510.0" styleClass="background-white" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="MyController">
    <children>
        <VBox prefHeight="886.0" prefWidth="1465.0" style="-fx-min-width: 100%;" AnchorPane.bottomAnchor="4.0" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="330.0" AnchorPane.topAnchor="10.0">
            <children>
                <TitledPane animated="false" minHeight="-Infinity" minWidth="-Infinity" prefHeight="880.0" prefWidth="1465.0" text="%app.pane.document">
                    <content>
                        <VBox minWidth="-Infinity" prefHeight="815.0" prefWidth="1474.0">
                            <children>
                                <TableView onMouseReleased="#handleRowSelect" fx:id="table" minHeight="-Infinity" minWidth="-Infinity" prefHeight="746.0" prefWidth="1450.0">
                                    .......
                                    <padding>
                                        <Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
                                    </padding>
                                </TableView>
                                <Pagination fx:id="pagination" prefHeight="73.0" prefWidth="1450.0" />
                            </children>
                        </VBox>
                    </content>
                </TitledPane>
            </children>
        </VBox>
    </children>
</AnchorPane>
...