java - JButton and its Location methods acting very weird -
my problem is, when create jbutton, whithin constructor, set location relative coordinates, x = 5, , y = 6, using following code:
this.setlocation(new point(x, y)); but after trying location using getlocation() method, returns 0,0. please note happens every jbutton trying place on grid layout powered jframe, , during debugging process, have noted location being instantiated.
can explain me why happens, , if can fix somehow?
edit:
the constructor (the brick class made, extends jbutton):
public brick(int posx, int posy) { this.setlocation(new point(posx, posy)); this.setvisible(true); } i make 100+ of them in 2 loops:
(int row = 0; row < 15; row++) { (int column = 0; column < 15; column++) { brick brickie = new brick(row, column); } } but afterwards, if wanna pick brick , check location this:
point bricklocation = brickie.getlocation(); both bricklocation.x == 0 , bricklocation.y == 0
you trying change button location when automatically assigned layout manager (your gridlayout). why getting same value - layout overwrites it.
to able change component bounds/location (including buttons) manually - have set "null" container's layout. after change location/size/bounds , affect components positions.
also don't need use "setvisible(true)" - default flag true components (even aren't displayed yet).
Comments
Post a Comment