• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Q: how to put a JPEG to the north region (of the frame's contentPane)

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am a beginner and reading �Head First Java 2nd Edition�.
I have finished the GUI Chapter and wanted to program some GUI Stuff, but there is one problem:

I�m overriding the paintComponent method:



and using it:



The Image (600x80) is not fully displayed. The width is O.K. but the height is only some Pixels (may be 5 or so).

It will be fully displayed when I put it to the center region:


� but I don�t want to have it in the center region, because center I do need for some other stuff.

I would be very happy if somebody could help me ;-)
[ July 19, 2007: Message edited by: G�rkan G�nay ]
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
unless you plan to do something else with LogoPanel, you don't need it.

change
frame.getContentPane().add(BorderLayout.NORTH, logo);
to
frame.getContentPane().add(BorderLayout.NORTH, new JLabel(new ImageIcon("logo.jpg"),JLabel.LEFT));

assumes you want the logo on the left (from drawImage(0,0)).
If not, modify JLabel.LEFT, to suit

[EDIT]
just reread your post, and see you are experimenting, so I haven't actually
answered your query.

when you put something in BorderLayout.NORTH (or any layoutManager 'position'),
the layoutManager uses the preferredSize of the component for sizing. Because
you have only drawn an image, and not given the panel a size, the layoutManager
in this instance (BorderLayout) uses the width of the frame (it is specified),
but the height is almost 0 (nothing is specified). It works in CENTER because CENTER
gets all remaining space. the apidocs for BorderLayout will
define it better than I can.

here's your code modified with some comments - see if you can follow the changes


[ July 16, 2007: Message edited by: Michael Dunn ]
 
G�rkan G�nay
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
WOW ! what a nice answer !
It works now and I haved learned a lot
Thank you very much.

P.S. This board seems to be a very cool one
 
reply
    Bookmark Topic Watch Topic
  • New Topic