JavaFX Menubar Released

Just a quick post to let anyone interested know that if you want a ‘Caspian-looking’ JavaFX menubar control, you can now find the one I was developing recently in the JFXtras project. It has not been included in any official release yet, so if you’re keen you’ll have to check it out from SVN.

There are a number of deficiencies with it, but certainly as a menubar it is functional. Since starting development on it my focus was on defining a simple API and locking it in. You can see an example of how to build a menubar if you’re interested. I’m pretty happy with how the API is now, so as the menubar improves you should feel fairly confident that you won’t need to update your code. In other words, please, use /Ā  thrash it and complain loudly (in a nice way) – it’s the only way you’ll get my attention. You can either email me privately (see contact details to the right), or leave a comment on this blog.

I hope this makes JavaFX a little more ‘enterprisey’. Hopefully soon we can have a number of extra JavaFX controls for people (like me) who build enterprise software.

28 thoughts on “JavaFX Menubar Released”

  1. Hi Jonathan,

    cool feature, but menubar should become member of JFXStage! Absolute positioning is ugly and always troubles with more complex layouts (MigLayout). So my suggestion is to add menubar to org.jfxtras.stage.JFXStage.

    JFXStage {
    menubar: myMenubar,
    content: [ …]
    };

    What do you think?

    Best,

    Thomas

    1. Thomas,

      This is the plan – it just needs someone to do it šŸ™‚ I might find some at some point to add this support in, but I couldn’t say when.

      — Jonathan

  2. Hi Jonathan,

    it’s me again. I’ve noticed that MenuBar seems to eat up MouseEvents.

    I have added println for button action in your sample code, but button is dead (had same behavior in my app after adding MenuBar).

    Button { translateX: 10, translateY: 10, text: “button” action: function() {println(“button pressed”);}}

    Any hint?

    Thomas

  3. Hi Jonathan, you’ve did nice work, thank you. I’m using your extension with pleasure.
    Please tell me, it there any possibility to specify skins for your MenuBar? I would like to change background color and font. Default font is not too good – it makes labels look like “jumping on the string”.

    1. Serega,
      Unfortunately it’s not easily skinnable right now, although it would be pretty trivial to extract the code so that you can use CSS to configure the colours.

      I will see if I can find time to do this.
      Cheers,
      Jonathan

  4. Hi, Jonathan.
    I’m trying to bind menu.width with scene.width. seems like I’m not good at JavaFX. I have a problem.

    org.jfxtras.scene.menu.MenuTest.fx
    You declare: var scene: Scene;

    And then, while describing menubar,
    you bind menubar.width with scene.width.

    I would like to separate my scene and menu bar to different files. Scene will be in main.fx, menuBar will be in MainMenu.fx

    And I don’t understand how to bind menu.width and scene.width if they are in different script-files.

    1. Serega,

      The simple answer is don’t split the files šŸ™‚

      Alternatively, create a class for the menubar where you pass the scene into it. That way the menubar can be bound to the scene’s width as per usual.

      — Jonathan

  5. Jonathan, I’ve tried to wrap menuBar into function:

    FILE MainMenu.fx:
    var mainMenu : MenuBar =null;

    public function getMenuBar(scene: Scene) : MenuBar{
    if(menuBar == null && scene =! null){
    //println(“init menuBar with scene.width={scene.width}”);
    menuBar = MenuBar{
    width: bind scene.width
    //some code goes here
    }
    }
    }

    FILE Main.fx:
    Stage{
    scene: scene = Scene{
    content:[ MainMenu.getMainMenu(scene)]
    }
    }

    And nothing happens. println says that scene.width = 0 while initializing mainMenu : MenuBar and mainMenu looks like it really sized to 0. (background gray color is not displayed).
    What do I do wrong?

  6. Excuse me, I’ve forgot to explain. My menu will be context-dependent, So I want to put all menu functionality into one file (show/hide some menus and sub-menus). That is why I would like to separate menu module from application entry point.

  7. Excuse for spam, I’ve found a solution, but I don’t think it’s beautiful enough.

    FILE MainMenu.fx:
    var mainMenu : MenuBar = null;
    public function getMainMenu(scene:Scene) : MenuBar{
    println(“getMainMenu invoke”);
    if(mainMenu == null && scene != null){
    println(“getMainMenu scene.width={scene.width}”);
    mainMenu = MenuBar{
    width: bind scene.width;
    //code
    }
    }

    FILE Main.fx
    var scene: Scene;

    scene = Scene{
    width: 800;
    content: [
    //mainMenu
    ]
    };
    insert MainMenu.getMainMenu(scene) into scene.content;
    //This code works… OMG. scene.width and mainMenu.width have been bound

    //And it doesn’t work:
    scene = Scene{
    width: 800;
    content: [
    MainMenu.getMainMenu(scene)
    ]
    };
    //Seems like scene looses initialization race with mainMenu?

  8. How can i use your MenuBar Package? I need it since MenuBar no longer avaible in JavaFX 1.2.

    Can you tell me, when JFXtras 0.6 will be release?
    Thx.

    1. Robert,

      MenuBar has never been available as a JavaFX control in JavaFX. If you want to use the JFXtras MenuBar that I have built, I would recommend you check it out from the JFXtras SVN repository. I don’t know when the JFXtras 0.6 release will be. Also, note that a future release of JavaFX will also have an official MenuBar control.

      Cheers,
      Jonathan

  9. hi, i have a problem with your menuBar.
    it seems your menuBar only work in ResizeableScene.

    unfortunately, i already create a project in Scene.
    When i change my Scene to ResizeableScene, all my nodes were scrambled.

    i want to keep Scene, but on the other hand i need your menuBar.do you have any opinion?
    Thx

    Regards,
    Robert

      1. Ohh… My mistake that i put MenuBar as first node in Scene.

        wow… are you working with JavaFX team? It’s a great job. I’m really envy of you.

        Btw, what if i want to make a RadioButtonMenuItem? (So bad, i can’t wait till Soma release).

        1. Robert,

          You’ll need to create it yourself, although there will likely be one available in the Soma release (I’ve already built it).

          Cheers,
          Jonathan

  10. Hello Jonathan!
    You’ve wrote:
    “””Also, note that a future release of JavaFX will also have an official MenuBar control.”””
    Where did you get this information? I’m doing my ph.d using JavaFX and I’m very interested in getting JavaFX roadmap, but I didn’t find any info.
    Please tell where do you get news about future releases?

      1. I’ve post there several bugs :).
        I’m learning this awesome technology with my students. OK, I’ll explore JavaFX jira to get more info.
        Thank you.

          1. It’s my pleasure to help to make JFX better. It’s really in 9000 greater than Silverlight or Flash. Only canvas can be compatible to JFX, but it’s too specialized solution.
            I have a question, is it planned to separate JFX css stuff from code? I think it’ll be very comfortable to change presentation properties of scene objectes in independent way from code.
            Just code and css tet files. šŸ™‚

          2. Serega,

            A lot of work is being done to improve CSS support, but I’m not sure how public that information is right now. I would recommend you keep an eye out for information in Soma, you should be happy with it.

            Cheers,
            Jonathan

  11. Hi Jonathan,

    I have an unique requirement, Please help me. I have an application window with one button and when clicking on the button I need to show list of menus below the button, Its same as clicking on a Menu in MenuBar. Here the challenge is I wanted to show the “child menus” in a Transparent window and simulate as if its a sub menus for the “button”.

    Let me explain the use case. Why I want this is, My Applet will be shown in a small area only with 30px height and When clicking on the “Button” I wanted to show the menu which will be bigger and should show on top of the other items which are below the applet. I am using the Transparent window so that my menus wont hide inside the applet container.

    Can you please help me on how to do this ? I tried adding the Menu and MenuItems in a VBox and added the VBox in a dialog. What’s happening is , MenuItems are displayed correctly but Menu’s are not rendered properly.

    Help me on how to get this resolved.

    gireeshkumar.g@gmail.com
    -Gireesh

Comments are closed.