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);
}});