Reputation: 1754
I have this very basic code which will be used to display tabs only when CheckMenuItem is selected:
CheckMenuItem toolbarSubMenuNavigation = new CheckMenuItem("Navigation");
toolbarSubMenuNavigation.setOnAction(new EventHandler<ActionEvent>()
{
@Override
public void handle(ActionEvent e)
{
// Show or hide tabs
System.out.println("subsystem1 #1 Enabled!");
}
});
This is the code that I want to show or hide when the check box is selected:
TabPane tabPane = new TabPane();
Tab tab0 = new Tab("blue");
tab.setContent(new Rectangle(200,200, Color.BLUE));
Tab tab1 = new Tab("green");
tab.setContent(new Rectangle(200,200, Color.GREEN));
tabPane.getTabs().addAll(tab0, tab1);
Can you tell me how I can show the tabs only when the CheckMenuItem is true? And I want to do this dynamically.
Upvotes: 1
Views: 1775
Reputation: 5032
Something like that can work
CheckMenuItem item = new CheckMenuItem();
Tab t = new Tab();
t.getGraphic().visibleProperty().bind(item.selectedProperty());
The item.selectedProperty() is true when is check, and false when it's not, so if you bind it to the visibleProperty() of your node it will visible when item is checked, and not visible when it's not checked
Upvotes: 3