java - Keeping a component in a fixed position within a BoxLayout -


i have jpanel uses horizontal box layout , contains jlabel keep in exact same position other components within jpanel setvisible(false). currently, jlabel moves left other components become invisible.

what's easiest way go this?

edit: pics added

so jpanel components visible

enter image description here

when set 3 jtextfields on right invisible, jlabel set text x moves left this:

enter image description here

but stay this:

enter image description here

edit2: i'm using netbeans gui editor's free design particular jlabel. i'm sorry mistake - i've been using lot of boxlayouts , got confused!

currently, jlabel moves left other components become invisible.

yes, layout managers designed work visible components. i'm not sure if of default layout manager work, using gridbaglayout, since layout based on grid structure long have components in grid on row label should not shift.

otherwise, dislay "other components" in panel using cardlayout. instead of making components invisible, swap panel empty panel.

read section swing tutorial on how use cardlayout more information , working examples.

edit:

based on picture easiest solution use "glue":

panel.add(box.createhorizontalglue); panel.add(xlabel); 

now label displayed @ far right of panel. read tutorial on how use boxlayout more information "glue".


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -