Terry,
Your assumption is correct; the sizes of screen components are
altered by the window decorations. But you can still make
the interior dimensions suit your needs.
There are various ways to go about this, but one simple one
would be to subclass JPanel and override the getPreferredSize()
method to set the size you want for the interior panel:
public Dimension getPreferredSize() {
return new Dimension(img.getWidth(), img.getHeight());
}
(assuming the height/width of the image are known at the time
the panel is created and displayed). This method will be called
internally when the panel is being created/displayed and the size
of the panel and the containing JFrame should be adjusted accordingly.
Chet.
> Delivered-To: [EMAIL PROTECTED]
> From: Terry Wu <[EMAIL PROTECTED]>
> Subject: [JAVA2D] Matching Frame Size with Image Size?
> To: [EMAIL PROTECTED]
>
> Hi,
>
> I am having the following problem:
>
> I'd like to open an image, draw it on a JPanel and then
> display it in a JFrame. I can get the image size by using
> the getWidth() and getHeight() methods of the BufferedImage.
> But I am having trouble to match the dimensions of JPanel
> or JFrame with that of an image. If I use the image width
> and height to setSize for JPanel or JFrame, a small portion
> of the image is always cut of in the JFrame at the bottom.
> I believe this is caused by the height of the title bar of
> JFrame makes the display area a bit smaller. I looked around
> and cannot find a solution. Can someone please suggest a
> get-around?
>
> Thanks in advance,
>
> Terry
>
> __________________________________________________
> Do You Yahoo!?
> Send instant messages & get email alerts with Yahoo! Messenger.
> http://im.yahoo.com/
>
>
=========================================================================
==
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
> of the message "signoff JAVA2D-INTEREST". For general help, send email
to
> [EMAIL PROTECTED] and include in the body of the message "help".
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".