0

I added a tabpane to my program with 2 tabs on it.

A table view is on the 1st tab

I want to click on a row of the table to switch to 2nd tab and show something there, but it fails.

Here is my simplified controller class:

@FXML
private TabPane myTabpane;

@FXML
private Tab tab1;

@FXML
private Tab tab2;

@FXML
private void handleClickTable(MouseEvent event) {
    if (event.getClickCount() == 2) {
        MyObject selectedObject = myTableView.getSelectionModel().getSelectedItem();
        doSomething(selectedObject);
    }
}

@FXML
void initialize(){

    myTabpane = new TabPane();

    tab1 = new Tab();

    tab2 = new Tab();
}


public void doSomething(MyObject myObject) {
    System.out.println("Mouse clicked! Let's do something with "+ myObject.getName());
    myTabpane.getSelectionModel().select(tab2);
}

I could get the println statement when I click on the table, but it do not switch to tab2. Can anybody point out what's wrong with my code? Thanks!

katana
  • 51
  • 4
  • Check out Slaw's answer on [this post](https://stackoverflow.com/questions/59253649/javafx-imageview-not-updating?noredirect=1#comment104784791_59253649) and more specifically the first section of his answer. In short, remove the three lines of code in your initialize method. – Robert Jan 10 '20 at 11:00
  • Thanks. It finally works. But what confuses me is that I didn't add those codes in my first attempt. It didn't work and throw an no pointer exception. That's why I added them. It now works just by deleting those 3 lines. – katana Jan 10 '20 at 18:21
  • Im glad it works. Whatever issue you had before must have been caused by something else which you then changed afterwards as well :) – Robert Jan 11 '20 at 00:54

0 Answers0