在TableView ScrollBar上添加监听器 [英] Add listener on TableView ScrollBar

查看:188
本文介绍了在TableView ScrollBar上添加监听器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这是我的.FXML:

 <?xml version =1.0encoding =UTF-8?> 

<?import java.lang。*?>
<?import javafx.scene.control。*?>
<?import javafx.scene.layout。*?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.control.cell。*?>
<?import javafx.collections。*?>
<?import fxmltableview。*?>

< BorderPane xmlns:fx =http://javafx.com/fxml/1xmlns =http://javafx.com/javafx/8.0.40
onContextMenuRequested = #showContextMenu >
< center>
< TableView fx:id =tableprefHeight =200.0prefWidth =300.0
BorderPane.alignment =CENTER>
< columns>
< TableColumn text =Name>
< / TableColumn>
< TableColumn text =Latitude>
< / TableColumn>
< TableColumn text =经度>
< / TableColumn>
< TableColumn text =Label>
< / TableColumn>
< TableColumn text =Label_two>
< / TableColumn>
< TableColumn text =Code>
< / TableColumn>
< TableColumn text =Code_two>
< / TableColumn>
< / columns>
< / TableView>
< / center>
< / BorderPane>

当我在TableView中添加项目时,ScrollBar会自动显示,我想添加到监听器上



我发现唯一的听众:

  table.setOnScroll(... 
table.setOnScrollTo(...

...只有当我用鼠标滚轮滚动时,不工作或工作。



我该如何解决?



编辑:我捕获了TableView中的所有事件,以查看当我滚动滚动条时显示哪个事件,显然是它传播的MouseDragged事件。

解决方案

这是我的解决方案与相同的发行。
滚动表:

  table.addEventFilter(ScrollEvent.ANY,event  - > 
PerformYourActionHere
);

拖动滚动条(我使用它,点击TableView标题即可得到排序t)

  table.addEventFilter(MouseEvent.MOUSE_CLICKED,event  - > {
if((event.getTarget()instanceof TableColumnHeader)| event.isDragDetect()){
PerformYourActionHere
}
});


I want to add a listener on my Tableview ScrollBar and i didn't find this listener in JavaFX.

This is my .FXML :

<?xml version="1.0" encoding="UTF-8"?> 

<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.control.cell.*?>
<?import javafx.collections.*?>
<?import fxmltableview.*?>

<BorderPane xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.40"
    onContextMenuRequested="#showContextMenu">
    <center>
        <TableView fx:id="table" prefHeight="200.0" prefWidth="300.0"
            BorderPane.alignment="CENTER" >
            <columns>
                <TableColumn  text="Name">
                </TableColumn>
                <TableColumn  text="Latitude">
                </TableColumn>
                <TableColumn  text="Longitude">
                </TableColumn>
                <TableColumn  text="Label">
                </TableColumn>
                <TableColumn text="Label_two">
                </TableColumn>
                <TableColumn text="Code">
                </TableColumn>
                <TableColumn text="Code_two">
                </TableColumn>
            </columns>
        </TableView>
    </center>
</BorderPane>

When i add items in TableView a ScrollBar appear automatically, and i want to add on a listener to do specific action when i scroll whith the scrollbar.

The only listener i found :

table.setOnScroll(...
table.setOnScrollTo(...

... doesn't work or work only if i scroll with the mouse wheel.

How can i solve this ?

EDIT : I captured all Event in the TableView to see which event i have to listen when i scroll with the scrollbar and apparently its a MouseDragged Event that is propagated.

解决方案

Here is my workaround with the same issure. Scrolling the table:

table.addEventFilter(ScrollEvent.ANY, event ->
    PerformYourActionHere
);

Drag the scroll bar (I use it with click on TableView "headers" to get sorting event as well)

table.addEventFilter(MouseEvent.MOUSE_CLICKED, event -> {
    if ((event.getTarget() instanceof TableColumnHeader) | event.isDragDetect()) {
        PerformYourActionHere
    }         
});

这篇关于在TableView ScrollBar上添加监听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆