0
votes

I have a JavaFx program which populates tableview with values. The table should display only 6 columns and the rest should be visible when scrolled.

But the scroll bar will not move when using mouse/keyboard. The horizontal scroll bar won't move either with mouse or the keyboard arrow keys. The vertical scroll atleast moves only with keyboard arrow keys.

I tried

Table.scrollTo(7);

It just scrolls down instead of horizontally. Uploading a screenshot of the image here. TableView.

2

2 Answers

0
votes

Use Table.scrollToColumnIndex(7);.

As for moving through the table with arrow keys. You need to enable cell selection to allow you to select single cells. Otherwise you only ever select complete rows which doesn't make TableView scroll horizontally:

Table.getSelectionModel().setCellSelectionEnabled(true);
0
votes

I also had the same issue but i resolved this by smart trick

 tableView.addEventFilter(ScrollEvent.SCROLL, (ScrollEvent event) -> {
                    ScrollBar hBar = getScrollBar(tableView, Orientation.HORIZONTAL);
                    if (event.getDeltaY() > 0 && event.isShiftDown()) {
                        if (hBar.getValue() != hBar.getMin()) {
                            hBar.setValue(hBar.getValue() - 20);
                            event.consume();
                        } else {
                            event.consume();
                        }
                    } else if (event.isShiftDown()) {
                        if (hBar.getValue() != hBar.getMax()) {
                            hBar.setValue(hBar.getValue() + 20);
                            event.consume();
                        } else {
                            event.consume();
                        }
                    }

                });

This will work and scroll horizontally with shift_key + mouse_scroll. Hope this will work for you too.. :)