• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need help with using layout.  RSS feed

 
Willie Tsang
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My problem is, I want my Jlabel to appear at the 0,0 location, as coded in the grdibagconstraints, but it appears in the center if i run this code. I already read alot of the apis, but it didn't help. Please help. Thanks


 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
add the additional 2 lines

c.weightx = 0.5;
c.weighty = 0.5;//<---
c.anchor = GridBagConstraints.NORTHWEST;//<---
 
Willie Tsang
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for reply, but when i change the values of
c.gridx = 0;
c.gridy = 0;
it stays at NORTHWEST.
is there a way to change its location according to the x,y?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could be wrong (usually am), but I have a sneaking suspicion you can't just 'place'
components here-and-there in GBL e.g. at 1,1 with no other components.

you may need to add a JPanel at 0,0 then use an appropriate layoutManager
for the panel to add your label where you want it.
 
Willie Tsang
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks alot for your post. Ill confirm that by reading the api, and mean while ill try different layouts. Thanks.
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Willie Tsang wrote:Ill confirm that by reading the api, and mean while ill try different layouts.

That word is "I'll" and is short for "I will" or "I shall"
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!