8 Replies Latest reply on Oct 26, 2012 8:10 AM by drenda81

    Arrow in menubar

      Hi guys,
      I've a small problem. I've a BorderPain and in the top I've a MenuBar with some MenuItem (1 ord two for every Menu). When I click in the menu the menu is opened but is displayed a down arrow and only one menuitem is displayed!!!

      It's very strage, infact after I clicked on the arrow the menu is show entirely and no arrow is displayed.

      Any suggestion?

      Thanks very much
        • 1. Re: Arrow in menubar
          Hi Guys,
          any idea about this problem?

          • 2. Re: Arrow in menubar
            David Grieve-Oracle
            Post some code.
            • 3. Re: Arrow in menubar
              Hi. The following works for me. WinXP, jdk7, javafx2.2
              public void start(Stage primaryStage) {
                      BorderPane bp = new BorderPane();
                      MenuBar menuBar = new MenuBar() ;
                      final Menu menu1 = new Menu("File");
                      final Menu menu2 = new Menu("Options");
                      final Menu menu3 = new Menu("Help");
                      menuBar.getMenus().addAll(menu1, menu2, menu3);
                      MenuItem mnItemPan_A = new MenuItem("Pane start");
                      MenuItem mnItemPan_B = new MenuItem("Pane end");
                      menu1.getItems().addAll(mnItemPan_A, mnItemPan_B);
                      StackPane root = new StackPane();
                      Scene scene = new Scene(root, 300, 250);
              • 4. Re: Arrow in menubar
                I'm using fxml for define my menu as this:
                <AnchorPane id="AnchorPane" prefHeight="768.0" prefWidth="1024.0" xmlns:fx="http://javafx.com/fxml" fx:controller="it.pianetatecno.odontox.ui.OdontoxController">
                    <BorderPane prefHeight="200.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
                        <StackPane fx:id="container" prefHeight="150.0" prefWidth="200.0" />
                         <MenuBar fx:id="menubar">
                            <Menu mnemonicParsing="false" style="&#10;&#10;&#10;&#10;" text="Lavori" fx:id="menuLavorazioni">
                                <MenuItem mnemonicParsing="false" onAction="#processLavorazioni" style="" text="Lavori" fx:id="itemLavorazioni" />
                            <Menu mnemonicParsing="false" style="" text="Contabilità" fx:id="menucontabilita">
                                <MenuItem mnemonicParsing="false" onAction="#processMovimenti" style="" text="Movimenti" fx:id="itemMovimenti" />
                            <Menu mnemonicParsing="false" style="" text="Anagrafiche" fx:id="menuAnagrafiche">
                                <MenuItem mnemonicParsing="false" onAction="#processProdotti" style="" text="Lavorazioni" fx:id="itemProdotti" />
                                <MenuItem mnemonicParsing="false" onAction="#processClienti" style="" text="Clienti" fx:id="itemClienti" />
                    <URL value="@odontox.css" />
                and this is the part of css:
                  -fx-text-fill: white !important;  
                  -fx-fill: red;        
                .menu .label
                    -fx-text-fill: white;
                    -fx-padding: 2px 4px 2px 4px;
                    -fx-font-size: 14px;
                But the result is pretty ugly: http://justpaste.it/1fw9

                • 5. Re: Arrow in menubar
                  David Grieve-Oracle
                  With the fxml you've posted, I do not see an arrow in the menu as shown in the image. Can you reproduce this outside of your application?
                  • 6. Re: Arrow in menubar
                    Sorry but that is all the code, there is no code in my application that display that arrow!! I don't know how is possibile that an arrow is displayed in that position without any row of code.

                    • 7. Re: Arrow in menubar
                      David Grieve-Oracle
                      The arrow comes from a style in caspian.css. You can see in caspian.css (extract it from jfxrt.jar, if necessary) that the style is such that the arrow isn't shown if the Menu is in a MenuBar. So the top-level menus are correct. If there is a Menu in the popup, then it will have an arrow. MenuItems do not have the arrow. This indicates to me that what you are seeing in the popup is a Menu and not a MenuItem. This is not consistent with the FXML you posted which shows only MenuItems as children of the Menus in the MenuBar.

                      Recheck your FXML. You must have a <Menu> where you intend a <MenuItem>
                      • 8. Re: Arrow in menubar
                        Sorry but that is the only code that create the menu. It's very strange infact in my scenebuilder in preview mode I've not this problem but after, when I run the application I have the arrow in the menu.
                        This is the controller of the main app where there is the menu:
                        public class OdontoxController implements Initializable {
                            private Main application;
                            @FXML //  fx:id="container"
                            private Pane container; // Value injected by FXMLLoader
                        //    @FXML //  fx:id="itemLavorazioni"
                        //    private MenuItem itemLavorazioni; // Value injected by FXMLLoader
                        //    @FXML //  fx:id="itemClienti"
                        //    private MenuItem itemClienti; // Value injected by FXMLLoader
                        //    @FXML //  fx:id="itemMovimenti"
                        //    private MenuItem itemMovimenti; // Value injected by FXMLLoader
                        //    @FXML //  fx:id="itemProdotti"
                        //    private MenuItem itemProdotti; // Value injected by FXMLLoader
                        //    @FXML //  fx:id="menuAnagrafiche"
                        //    private Menu menuAnagrafiche; // Value injected by FXMLLoader
                        //    @FXML //  fx:id="menuLavorazioni"
                        //    private Menu menuLavorazioni; // Value injected by FXMLLoader
                        //    @FXML //  fx:id="menubar"
                        //    private MenuBar menubar; // Value injected by FXMLLoader
                        //    @FXML //  fx:id="menucontabilita"
                        //    private Menu menucontabilita; // Value injected by FXMLLoader
                            @FXML //  fx:id="vbox"
                            private VBox vbox; // Value injected by FXMLLoader
                            @FXML //  fx:id="headerApp"
                            private Pane headerApp; // Value injected by FXMLLoader
                            @Override // This method is called by the FXMLLoader when initialization is complete
                            public void initialize(URL fxmlFileLocation, ResourceBundle resources) {
                        //        assert itemClienti != null : "fx:id=\"itemClienti\" was not injected: check your FXML file 'Odontox.fxml'.";
                        //        assert itemLavorazioni != null : "fx:id=\"itemLavorazioni\" was not injected: check your FXML file 'Odontox.fxml'.";
                        //        assert itemMovimenti != null : "fx:id=\"itemMovimenti\" was not injected: check your FXML file 'Odontox.fxml'.";
                        //        assert itemProdotti != null : "fx:id=\"itemProdotti\" was not injected: check your FXML file 'Odontox.fxml'.";
                        //        assert menuAnagrafiche != null : "fx:id=\"menuAnagrafiche\" was not injected: check your FXML file 'Odontox.fxml'.";
                        //        assert menuLavorazioni != null : "fx:id=\"menuLavorazioni\" was not injected: check your FXML file 'Odontox.fxml'.";
                        //        assert menubar != null : "fx:id=\"menubar\" was not injected: check your FXML file 'Odontox.fxml'.";
                        //        assert menucontabilita != null : "fx:id=\"menucontabilita\" was not injected: check your FXML file 'Odontox.fxml'.";
                                assert vbox != null : "fx:id=\"vbox\" was not injected: check your FXML file 'Odontox.fxml'.";
                                // initialize your logic here: all @FXML variables will have been injected
                            private void start() {
                            public void setApp(Main application) {
                                this.application = application;
                            // Handler for Menu[fx:id="menuLavorazioni"] onAction
                            public void processLavorazioni(ActionEvent event) {
                                try {
                                    LavoriController controller = (LavoriController) replaceSceneContent("lavori/Lavori.fxml");
                                } catch (Exception ex) {
                            public void processNuovaLavorazione(ActionEvent event) {
                                try {
                                    LavoriDettaglioController controller = (LavoriDettaglioController) replaceSceneContent("lavori/LavoriDettaglio.fxml");
                                } catch (Exception ex) {
                            // Handler for Menu[fx:id="menuLavorazioni"] onAction
                            public void processClienti(ActionEvent event) {
                                try {
                                    ClientiController controller = (ClientiController) replaceSceneContent("clienti/Clienti.fxml");
                                } catch (Exception ex) {
                            // Handler for MenuItem[fx:id="itemMovimenti"] onAction
                            public void processMovimenti(ActionEvent event) {
                                try {
                                    MovimentiController controller = (MovimentiController) replaceSceneContent("movimenti/Movimenti.fxml");
                                } catch (Exception ex) {
                            // Handler for MenuItem[fx:id="itemProdotti"] onAction
                            public void processProdotti(ActionEvent event) {
                                try {
                                    ProdottiController controller = (ProdottiController) replaceSceneContent("prodotti/Prodotti.fxml");
                                } catch (Exception ex) {
                            public Initializable replaceSceneContent(String fxml) throws Exception {
                                FXMLLoader loader = new FXMLLoader();
                                InputStream in = OdontoxController.class.getResourceAsStream(fxml);
                                loader.setBuilderFactory(new JavaFXBuilderFactory());
                                AnchorPane page;
                                try {
                                    page = (AnchorPane) loader.load(in);
                                } finally {
                                    if (in != null) {
                                return (Initializable) loader.getController();
                        As you can see I have commented the code that refers the menu as test but not even in this case the menu works fine.

                        Any ideas?