Monday, March 19, 2012

Layout Panes in JavaFX 2.0

Creating a graphical user interface that looks nice and that provides a good usability is a very common task in software development. Fortunately JavaFX 2.0 offers great support in that area.

What is a layout manager and why do we need them?

Layout managers are regions or areas that follow individual rules to (re)arrange and to (re)size all their children in relation to their own size. Generally, it is also possible to specify a fixed position of your components in an application window. But how should the window know what to do when you resize your application window? Should it leave the new available space blank? Should some components “vanish” if you make the window smaller? Should it resize some components? If yes, which one and how?

These questions show, why layout managers are necessary in software development.

Facts about layout managers in JavaFX 2.0

  • In JavaFX 2.0 layout managers are called “panes”
  • Every layout pane extends the Region class
  • To create your own layout pane, it is highly recommended to extend Region yourself
  • Types of layout panes in JavaFX 2.0
    • HBox (lays out its children in a horizontal row)
    • VBox (lays out its children in a single vertical column)
    • Border Pane (lays out its children in five different regions: Top, Right, Bottom, Left and Center)
    • Anchor Pane (similar to a Border Pane, differences will be covered in detail)
    • Flow Pane (lays out its children censecutively one after another)
    • Tile Pane (similar to a Flow Pane, differences will be covered in detail)
    • Stack Pane (lays out its children by putting them on top of each other on one single stack)
    • Grid Pane (lays out its children in a grid of columns and rows)
  • There are some “false friends” in JavaFX 2.0 regarding layout panes:
    • Tab Pane, Titled Pane and Split Pane. These extend Control and not Region. These are no layout managers/panes, as they do not (re)arrange or (re)size their children.
  • Every layout pane provides a setPadding method defined in the Region class. With this method you can tell a pane to layout its children with the specified padding around them.
  • Almost every layout pane (AnchorPane being the only exception) provides a setAlignment method. This method specifies how the layout pane aligns and arranges all children inside the layout pane.
  • Almost every layout pane (AnchorPane again being the only exception) provides a static setMargin method. With this method you can give one or more certain nodes inside the pane a specific margin that the parent will keep around it when layouting its children.

In the next few posts I´ll give 1 or 2 examples for every layout pane in JavaFX 2.0.


5 comments:

  1. May I just say whаt a сomfort to
    dіsсοvеr sοmеbody that
    rеallу knows what they are discuѕsing
    on the web. Υou dеfinitely understand hoω
    to bгing an iѕsue to lіght and make it impoгtant.
    A lot moгe ρeoplе really neеd to reaԁ this and understаnd this side
    of the stoгy. It's surprising you are not more popular since you surely possess the gift.

    Feel free to surf to my webpage hemorroides

    ReplyDelete
  2. These are іn fact impгessive idеas іn οn the topіc of blοggіng.
    You have touched ѕome fastiԁious points here.
    Any waу keeр up wrintіng.

    Feel freе to visit mу webpage :: hemorroides internas

    ReplyDelete
  3. My brother suggestеd I mіght like this blog.
    He was еntirely гight. This роst аctually made my ԁay.
    You cаnn't imagine simply how much time I had spent for this information! Thanks!

    Also visit my webpage: Onlineeducationexperience.com

    ReplyDelete
  4. I don't even know the way I finished up here, but I assumed this submit used to be good. I do not understand who you are but certainly you are going to a famous blogger when you are not already. Cheers!

    My web blog :: hemroid

    ReplyDelete
  5. Eхcellеnt articlе. Κеep writing ѕuch kinԁ
    of informatiοn οn your blog. Im гeally impressed bу it.


    Hi there, Υou haѵе реrformеԁ an incrediblе jοb.
    I'll definitely digg it and for my part suggest to my friends. I'm sure thеy'll be benefited from this website.

    my homepage - emorroide

    ReplyDelete