• Post Reply Bookmark Topic Watch Topic
  • New Topic

Centering in a JPanel

 
cardwell cupp
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How would I center a component into the middle of a JPanel? I can center it horizontally, but not vertically. Any suggestions
Thanks
Cardwell
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
set your layout to null, and mathmatically find the center of your JPanel.
I.E
JPanel size = 100 x 100
Component size = 10 x 10
Center of JPanel is x = (Panelwidth/2)-(ComponentWidth/2)
and the same for Y
Center = (x, y)

------------------
Happy Coding,
Gregg Bolinger
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!