• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Centering a JComponent in the CENTER area of BorderLayout?

 
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
simple demo using GridBagLayout and a JLabel (don't know what your JComponent is)

 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic