I have a tab pane that contains a bunch of tabs (obviously). Normally you can set a listener to each tab by calling setOnSelectionChanged()
on the Tab. However, if the TabPane is being reorganized in some way, the tab pane automatically selects the first tab in the list. This is causing some performance issues for me so I would like to know if there is a way to know if a Mouse Click caused the Tab to be selected. Apparently tabs cannot have onMouseClick()
listeners.

- 197
- 1
- 9
-
It might be worth addressing the performance issues first. – trashgod Dec 26 '17 at 17:39
-
Yeah, I have been trying to do that for the last two days, made significant improvements but still have work to do. This was an avenue I was exploring. Wish there was a way to either do the above or force the tab pane to not select anything in the first place. – Khalid Akash Dec 26 '17 at 18:11
-
It sounds like you're trying to fix a model problem in the view. Instead, use a `javafx.concurrent.Worker` and update relevant properties so that tab selection is not delayed. – trashgod Dec 27 '17 at 16:25
-
Yeah I was applying a new 'model' everytime the tab changed by recreating the entire view from the changed model, instead of applying the model to whats already there. I was able to get a 400% performance boost. :D This question no longer needs to be answered but I guess I'll leave it up just in case anyone has a solution and someone else might need it. – Khalid Akash Dec 27 '17 at 19:41
1 Answers
Whilst the solution to the answer wasn't found since tabs aren't actually nodes and don't have mouse click listeners, the performance issues were solved.
When changing tabs, I was (lazily) recreating the entire view and applying the model to the view. This caused a delay of approximately 140ms or more every time the tab changed. It was a bigger issue when implementing a search box to find the correct tab because as the tabs were being recreated from the search, the views were being recreating as the selection of the tabs changed (Tab pane automatically selects the first tab when adding new tabs).
Ultimately the design was changed to having the controller create the view once, and simply hooking the model to the view as the tab changed instead of recreating the view over and over.
I highly recommend looking at this post if your having performance issues and are relatively new to MVC/JavaFX programming:
Currently changing tabs take approximately 15ms which is a significant improvement!

- 197
- 1
- 9