java - GridBagLayout - I cant move my Objects -
im working on understanding gridbaglayout @ moment , have following code:
public static void main(string[] args) { jframe myframe = new jframe(); myframe.setsize(400,400); myframe.setdefaultcloseoperation(jframe.exit_on_close); myframe.setlocationrelativeto(null); jpanel panelmain = new jpanel(new gridbaglayout()); gridbagconstraints c = new gridbagconstraints(); c.gridx = 3; c.gridy = 0; c.weightx = 0.5; c.weighty = 0.5; c.anchor = gridbagconstraints.first_line_start; panelmain.add(new jbutton("first name: "),c ); myframe.add(panelmain); myframe.setvisible(true); i lack basic knowledge of understanding layoutmanager, want understand it. code creates frame panel button "first name: " @ top left of frame (eventhough gridx = 3, gridy = 0 thought define position of object). doesnt matter how change those). read tons of posts etc. not how move button. played around gridx, weightx, ... everything. either in top left or in centre.. doing wrong? whats missing? apprecciate kind of help
Comments
Post a Comment