Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Frame size of picture ?

Status
Not open for further replies.

domenu

Programmer
May 31, 2002
30
BE
Hey,

I am writing a small program, and it has to display a simple picture in a window (JFrame).I can draw and display the pic, but when I use frame.pack(), the size of the frame is too small to display the pic!
I have drawn the pic on a regular JPanel with drawImage() in the paintComponent() method.

Can anybody tell me how to size the frame that it shows the entire picture ?

Thanks,

nick
 
You could use :
Code:
    frame.setSize(image.getWidth(null) + 20, image.getHeight(null) + 20);
And remove "frame.pack". (PS : If you have other stuff besides the image in the frame, you'll have to adjust the width and heigth).
 
Sorry, correction : Since your image is already on a JPanel, you can better do the following :
Code:
    panel.setPreferredSize(new Dimension(image.getWidth(null), image.getHeight(null)));
And leave "frame.pack();" in.
Maybe you want to add (as of jdk1.4 if I'm right)
Code:
  f.setUndecorated(true);
 
Thanks for the tip, hologram !

This is the working version of the code :
>>
>>panel.setPreferredSize(new Dimension(image.getWidth(null), image.getHeight(null)));
>>frame.getContentPane().add(panel,BorderLayout.CENTER);
>>frame.pack();
>>frame.setVisible(true);
>>
Cheers,

nick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top