• Post Reply Bookmark Topic Watch Topic
  • New Topic

Centering a JComponent in the CENTER area of BorderLayout?

 
Joe Vahabzadeh
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All,

I've got a JFrame whose contentPane has the typical BorderLayout setup.

I want to put a JComponent in the BorderLayout.CENTER area, so I do the following:


Naturally, since myJComponent is the ONLY thing that's been added, since it's in the CENTER, the component is expanded to fill the entire contentPane, as the red border will indicate.

HOWEVER, the actual visible part of myJComponent then gets shoved into the upper-left corner, whereas I want it centered both horizontally and vertically.

I've tried using setAlignmentX and setAlignmentY on the myJComponent to no avail. I have a feeling I'm missing something dreadfully obvious, but can't figure out what it is.

Thanks in advance for any guidance anyone can give me on this.
[ February 22, 2008: Message edited by: Joe Vahabzadeh ]
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
simple demo using GridBagLayout and a JLabel (don't know what your JComponent is)

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!