java - Align the label column of different DesignGridLayout -


consider 2 jpanel instances using designgridlayout, following:

jframe demoapplicationframe = new jframe(); jpanel singledesigngridlayout1 = new jpanel(); designgridlayout layout1 = new designgridlayout(singledesigngridlayout1); layout1.row().grid(new jlabel("short lbl1")).add(new jtextfield("")); layout1.row().grid(new jlabel("short lbl2")).add(new jtextfield(""));  jpanel singledesigngridlayout2 = new jpanel(); designgridlayout layout2 = new designgridlayout(singledesigngridlayout2); layout2.row().grid(new jlabel("a bit longer label"))     .add(new jtextfield("")); layout2.row().grid(new jlabel("another long label here"))     .add(new jtextfield(""));  demoapplicationframe.getcontentpane().add(singledesigngridlayout1,      borderlayout.north); demoapplicationframe.getcontentpane().add(singledesigngridlayout2,     borderlayout.south); 

executing code, create window:

window screenshot

is possible align column labels of 2 panels?

is possible align column labels of 2 panels?

no it's not because designgridlayout works grids within same container. if components placed in different panels there's nothing designgridlayout can ensure alignment of cross-panels components.

in context can workarounds (if any). aware of this: should avoid use of set(preferred|maximum|minimum)size methods in java swing? yes, should. setting fixed labels size not option either.


some thoughts

i thinking matter , it's not designgridlayout limitation how layout managers work. if take how layout managers work section of laying out components within container lesson, states this:

  1. layout managers 2 things:

    • calculate minimum/preferred/maximum sizes container.
    • lay out container's children.

layout managers based on provided constraints, container's properties (such insets) , on children's minimum/preferred/maximum sizes. if child container own layout manger used minimum/preferred/maximum sizes , lay out.

this means if child container may have own layout manager lay out own children components. property makes container independent of ancestor (about laying out components). if had "global" (just name somehow) layout manager aligns components within 2 separate containers, breaking aforementioned contract because children containers wouldn't independent of ancestors.

i'm relatively new layout managers stuff don't know layout manager allows need (or feel need), because don't have to, actually. imho should reconsider if need panels or can manage components in single container. maybe there's more suitable layout manager needs in list:


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -