java - SetLayout Function main purpose -
public void init_numsolvers() { (x = 0; x < 9; x++) { n++; num[x] = new button("" + n); add(num[x]); num[x].setbounds(num_x, num_y, 40, 40); setlayout(null); num_x += 40; }
why setbounds() function doesn't work without setlayout(null) want understand main purpose of setlayout(null) function
you want read tutorials , api spell out setbounds , setlayout does, briefly:
- the
setlayout(...)
method allows set layout of container, jpanel, flowlayout, borderlayout, gridlayout, null layout, or whatever layout desired. layout manager helps lay out components held container. - the
setbounds(...)
method used set location , size of single component, , useful ifnull
layout used container holds component. - when set layout null, tell container using no layout @ all, , programmer responsible setting sizes , positions of components added container.
- having said this, should strive avoid using
null
layouts ,setbounds(...)
. while newbie swing programmer, may seem easiest way create complex layouts, when using them create gui's might on 1 platform only. more importantly, create gui's impossible maintain , upgrade without causing subtle bugs. don't use them if @ possible. - please read official layout manager tutorials on explained there.
note code repeatedly sets container's layout null within loop. have no idea why repeatedly since need , want set container's layout once.
Comments
Post a Comment