Run a method if tab is clicked

469 views Asked by At

I would like to run a function when a Tab is clicked. I tried to do this in my fxml but I think Tabs do not have an onAction property to call.

<Tab fx:id="Tab1" text="Tab1" onAction="#loadTab1"> 

</Tab>

So I get this error when I run the application:

Caused by: java.lang.UnsupportedOperationException: Cannot determine type for property.
1

There are 1 answers

0
Ricky On BEST ANSWER

One simple solution to register the tab selection is this:

Tab1.setOnSelectionChanged(e -> {
            System.out.println(Tab1.isSelected() ? "Tab1 is selected" : "Tab1 is not selected" );
        });