resize - Java Layout Managers -
what benefits of using existing layout manager opposed writing listener handles resizing functions? instance, needed arrange buttons in grid , center grid:
int h = component.getheight() / 11; int w = component.getwidth() / 9; int offsetx = w; int offsety = h; int x = (2 * column) * w - offsetx; int y = (2 * row) * h - offsety; setbounds(x, y, w, h);
instead of fumbling around layout manager wrote small bit of code activated buttons whenever jpanel resized. if use layout manager, more cumbersome write code arrange , if add component jpanel, things more complex opposed adding few additions or subtractions.
so given this, there benefits using layout manager in situation or few customized lines easier use , maintain?
your code mimicking gridlayout
.
setlayout(new gridlayout(11, 9)); // add components ... // profit
to center it:
jpanel outerpanel = new jpanel(new borderlayout()); jpanel gridpanel = new jpanel(new gridlayout()); outerpanel.add(gridpanel, borderlayout.center);
Comments
Post a Comment