• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

problem with label

 
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
 
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.
 
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
 
Everybody's invited. Even this tiny ad:
create, convert, edit or print DOC and DOCX in Java
https://products.aspose.com/words/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!