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 Responses to “JavaFX Menubar Released”


  • 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

    • 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

  • 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

  • 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”.

    • 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

  • Jonathan, thx for your feedback. After update from SVN (rev 298) it now works.

    Bye, Thomas

  • 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.

    • 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

  • 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?

  • 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.

  • 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?

  • 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.

    • 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

  • 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

  • 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?

    • Serega,

      I’m in the JavaFX team, that’s where I get the news :-)
      But there is the http://javafx-jira.kenai.com/ issue tracker that has a lot of information about what is happening in the JavaFX world.

      Cheers,
      Jonathan

      • 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.

        • Great to hear you’re reporting issues to the issue tracker. If you’re interested in tracking the menu/menubar control, it is http://javafx-jira.kenai.com/browse/RT-5513.

          Cheers,
          Jonathan

          • 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. :)

          • 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

  • Jonathan,

    Is there an example source code available, the link posted above:
    http://code.google.com/p/jfxtras/source/browse/jfxtras.core/trunk/test/org/jfxtras/scene/menu/MenuTest.fx
    is no longer available.

    Thanks,
    George

  • 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 currently closed.

About

Jonathan Giles is a 29 year old software engineer living in Palmerston North, New Zealand. He holds a Bachelor of Engineering Honours in Software Engineering, a Masters of Science in Computer Science, and is a Sun certified Java programmer. Jonathan specialises in Java, Swing, JavaFX and Client-Server development.

He is currently the tech lead at Oracle in the JavaFX UI controls team, and a Java evangelist. He also blogs over at the FX Experience blog. Obviously, the opinions expressed here are his own.

Contact

Email:   Here
NZ:   +64 22 1985 001
Twitter:   JonathanGiles
LinkedIn:   My Profile
Google+:   +JonathanGiles
Skype:   Skype Me