This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with label

 
Andrew Lit
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, this is what i have

when i resize my frame, buttuns are being centered, but my label - no. Label stays on the left of the frame. Why is it so? What changes should i make?
thank you in advance
 
Ashish Hareet
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Andrew,
Go thru the code snippet provided in the docs & you'll get an idea about what's going wrong or try adding another component to "panel" & you'll realise why your label is not being centered.
HTH
Ashish Hareet
 
Andrew Lit
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I chaged the line

into

but nothing changed.
 
anand pillai
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Andrew,
I have added two more panels to solve ur problem , no it works as u wish

JPanel panel = new JPanel();
JPanel panel1 = new JPanel();
JPanel panel2 = new JPanel();
panel.setBorder(BorderFactory.createEmptyBorder(30,30,100,30));
panel1.setLayout(new GridLayout(1,2));
panel.setLayout(new GridLayout( 2, 1));
panel1.add(button);
panel1.add(button1);
panel2.add(label);
panel.add(panel1);
panel.add(panel2);
return panel;
Anand
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic