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!