package graphics.api.control.menu; import javafx.scene.input.MouseEvent; import javafx.event.EventHandler; import javafx.application.Application; import javafx.stage.Stage; import javafx.scene.Scene; import javafx.scene.control.MenuBar; import javafx.scene.control.Menu; import javafx.scene.control.MenuItem; import javafx.beans.value.*; import javafx.beans.property.StringProperty; import javafx.scene.Group; import javafx.scene.control.RadioButton; public class CouldNotEnableDisableMenuBar extends Application { public static void main(String[] args) { CouldNotEnableDisableMenuBar.launch(args); } RadioButton addMenuBar = new RadioButton(); MenuBar menuBar = new MenuBar(); @Override public void start(Stage stage) throws Exception { float h = 400; float w = 400; Scene scene; final StringProperty RADIOBUTTONLABEL = new StringProperty("Disable MenuBar"); addMenuBar.setTranslateX(30.0F); addMenuBar.setTranslateY(50.0F); addMenuBar.textProperty().bind(RADIOBUTTONLABEL); addMenuBar.setSelected(false); addMenuBar.setOnMouseClicked(new EventHandler() { @Override public void handle(MouseEvent me) { if (addMenuBar.isSelected()) { RADIOBUTTONLABEL.setValue("Enable MenuBar"); } else { RADIOBUTTONLABEL.setValue("Disable MenuBar"); } } }); menuBar.setDisable(addMenuBar.isSelected()); addMenuBar.selectedProperty().addListener(new InvalidationListener() { public void invalidated(ObservableValue ov) { menuBar.setDisable(addMenuBar.isSelected()); } }); Menu menu = new Menu("File"); MenuItem menuitem = new MenuItem(); menuitem.setText("New"); MenuItem menuitem2 = new MenuItem(); menuitem2.setText("Open"); menu.getItems().clear(); menu.getItems().addAll(menuitem, menuitem2); Menu menu2 = new Menu("Edit"); MenuItem menuitem6 = new MenuItem(); menuitem6.setText("Cut"); menu2.getItems().clear(); menu2.getItems().addAll(menuitem6); menuBar.getMenus().clear(); menuBar.getMenus().addAll(menu, menu2); scene = new Scene(new Group(), w, h); ((Group) scene.getRoot()).getChildren().clear(); ((Group) scene.getRoot()).getChildren().addAll(menuBar, addMenuBar); stage.setScene(scene); stage.setVisible(true); } }