I want to create a JLabel (containing an image) in the north position of a border layout that auto-sizes to a length matching the preferred width of a component in the center position of a border layout.
The only way I can do this at present is to create another panel in the north position and add the label in the center position of this panel.
Is there a way to do this without the extra panel?
There is no need to add extra panel, As I see that you only need Label in North (i.e. Top).
Components added to north in borderlayout will occupy complete width and height will be preffered height of component. This is decided on various factors.
You just need to take care of setting label text and image in center. Look at alignment api’s of label for same.
Details:
http://www.ehow.com/way_5579409_java-borderlayout-tutorial.html
e.g.
http://www.java2s.com/Tutorial/Java/0240__Swing/1340__BorderLayout.htm
http://download.oracle.com/docs/cd/E17409_01/javase/tutorial/uiswing/layout/border.html