4
有没有办法知道表格视图中是否存在滚动条? (除了我在下面的代码中所做的) 我的目标是在桌子的右侧(在桌子上)放置2个箭头图像(以关闭/打开侧面板)。但我不想把它们放在滚动条上。 表格内容是搜索的结果,所以有时滚动条可见,而其他时间则不可见。如果没有足够的物品。 我希望我的箭头位置每次改变tableview项目时都会改变。如何知道JavaFx中是否显示滚动条TableView
我已经尝试了以下解决方案,但结果是第二次移动箭头进行搜索。看起来像一个并发问题。就像我的侦听器代码在呈现表之前执行一样。
有没有办法解决这个问题?
tableView.getItems().addListener((ListChangeListener<LogData>) c -> {
// Check if scroll bar is visible on the table
// And if yes, move the arrow images to not be over the scroll bar
Double lScrollBarWidth = null;
Set<Node> nodes = tableView.lookupAll(".scroll-bar");
for (final Node node : nodes)
{
if (node instanceof ScrollBar)
{
ScrollBar sb = (ScrollBar) node;
if (sb.getOrientation() == Orientation.VERTICAL)
{
LOGGER.debug("Scroll bar visible : {}", sb.isVisible());
if (sb.isVisible())
{
lScrollBarWidth = sb.getWidth();
}
}
}
}
if (lLogDataList.size() > 0 && lScrollBarWidth != null)
{
LOGGER.debug("Must move the arrows images");
tableViewController.setArrowsDistanceFromRightTo(lScrollBarWidth);
}
else
{
tableViewController.setArrowsDistanceFromRightTo(0d);
}});