2

When I use a TabPane with a touchscreen, the tabs are switching when I swipe left or right, which I want to prevent.

I fixed part of the problem by consuming the swipe events on the child panes, but the tabs still switch when I swipe in the area where the tabs are displayed.

I tried to consume the events that the TabPane generates, such as the swipe and scroll events, but the tabs are still switching. How do I prevent this from happening?

Kretep
  • 514
  • 2
  • 4
  • 12
  • See if [this](https://stackoverflow.com/questions/42256969/javafx-tabpane-disable-tab-switching-by-keys) answer helps. – SedJ601 Nov 30 '17 at 14:42
  • I tried making the TabPane not focus traversable, but it still gets the focus when I swipe. (The answer you refer to is more to make a scrollbar get the focus, instead of disabling the tab switching behavior) – Kretep Nov 30 '17 at 14:54
  • I am going to guess that you will have to do event filtering and consume that event. – SedJ601 Nov 30 '17 at 15:02
  • If I only knew what event to filter for :) None of them seem to do the trick – Kretep Nov 30 '17 at 16:05
  • 1
    https://stackoverflow.com/questions/22257729/javafx-equivalent-to-java-awt-eventqueue <- go here and add an `EventFilter` to your `Scene`. Use `System.out.println(event.getEventType());` to figure out which event is being fired. Handle the event accordingly. – SedJ601 Dec 01 '17 at 15:24
  • 1
    I followed your suggestion and it turns out that the swipe events are targeted at an unidentified StackPane (I'm assuming some internal component of the TabPane). Consuming those events seem to do the trick. The only thing is that I now only check for the type of the event target and I don't see how I can be sure that that StackPane actually belongs to the TabPane. But for now it works! – Kretep Dec 06 '17 at 20:39
  • 1
    [ScenicView](http://fxexperience.com/scenic-view/) could probably help you see that `StackPane`. – SedJ601 Dec 06 '17 at 20:42

1 Answers1

0

I add the same problem. I solved adding the following filter to the tabPane:

   tabPane.addEventFilter(SwipeEvent.ANY, new EventHandler<SwipeEvent>() {

        @Override
        public void handle(SwipeEvent event) {
            event.consume();
        }
    });
Ramon
  • 11
  • 1