Add event (action) when switching tab

Asked

Viewed 797 times

1

I have a Tabpane in my project that contains 3 different tabs, I would like to know how to add an event when changing "tab" in Javafx.

For example, by clicking on the "address" tab, create an event for me to add functionality to that tab.

Guys, this is how I did it:

Worked :)!

    @FXML private TabPane tabPane;


 tabPane.getSelectionModel().selectedItemProperty().addListener(new ChangeListener() {

        @Override
        public void changed(ObservableValue observable, Object oldValue, Object newValue) {
            System.out.println("Tab Selection changed");

            labelFruto.setText(fruto.getFruto());
        }



    });

1 answer

1


  • Hello Math, okay!! Would this "Number" be the number corresponding to the "tab" selected? Where I identify the tab that is being selected?

  • @Sarafernandes believe not, I’ve worked hard with Javafx, however I have not installed it on my machine, I will install and do some tests. However, I believe that you have to take the object of each tab of this and write this code to them, changing the name of the object where it is written tabPane. Ever tried it like that? Made a mistake?

  • I did the following, I created the tab identification " @FXML private Tab tabCondSecagem" but unfortunately it is not working. I believe it was supposed to work!!... But I’m trying here right here right!!

  • Hello Math , I did as you mentioned, I changed only the arguments from within the function "public void changed()"... See above how it turned out!! And then it worked!! Thank you so much for your help :)!

  • @Sarafernandes :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.