I have a custom class extending JDialog. Within this dialog window I'm
going to have multiple JPanels to organize the textfields. I want to
show a jpeg photo of people in this dialog and to have more control over
where the image goes (since it isn't possible to simply add an image to
a JPanel as far as I know) I created a private class extending JPanel
and it only holds an image.
I create an instance of this "photo" panel and add it to one of the
panels in my dialog window. So the photo is basically embedded in a
total of 2 JPanels and then the JDialog. The problem is that I only get
a small white box when I display the image this way. If I instead place
the image directly into a JPanel in my dialog the image shows up. This
method causes the photo to only be embedded in 1 JPanel instead of 2.
I've tried resizing the dialog window and it didn't help. The
ImageObserver for the photo is the custom JPanel class which is the
first JPanel the image is placed in and I've modified the paint() method
of the JPanel to attempt to make the photo show up. When I use the
other method I modify the paint() method of the JDialog and it works.
any ideas?
thanks
Brandon McCombs schreef:
> I have a custom class extending JDialog. Within this dialog window I'm
> going to have multiple JPanels to organize the textfields. I want to
[quoted text clipped - 19 lines]
>
> thanks
My guess is you're having a layout manager problem, but without seeing
some actual code it's hard to help you out.
Regards,
Bart
> I have a custom class extending JDialog. Within this dialog window I'm
> going to have multiple JPanels to organize the textfields. I want to
[quoted text clipped - 19 lines]
>
> thanks
I'd add a JLabel to the panel and set the labels icon to the image.
Remember that you may need scale the image for the size of the panel if
you want to keep aspect ratio's and have a certain size .....
I use code a bit like this :-
final Image scaledImage = scaleImage(originalOverviewImage,
overviewPanel.getWidth(), myPanel.getHeight());
final ImageIcon myIcon = new ImageIcon(scaledImage);
final JLabel label = new JLabel(myIcon, SwingConstants.CENTER);
myPanel.add(label, BorderLayout.CENTER);
private Image scaleImage(final Image originalImage, final int width,
final int height) {
Image newImage = null;
if (originalImage != null) {
final double originalHeight = originalImage.getHeight(this);
final double originalWidth = originalImage.getWidth(this);
final double heightScale = height / originalHeight;
final double widthScale = width / originalWidth;
final double scale = heightScale < widthScale
? heightScale
: widthScale;
final int newHeight = (int) (originalHeight * scale);
final int newWidth = (int) (originalWidth * scale);
newImage = originalImage.getScaledInstance(newWidth, newHeight,
Image.SCALE_DEFAULT);
}
return newImage;
}
Brandon McCombs - 26 Jul 2006 04:00 GMT
>> I have a custom class extending JDialog. Within this dialog window I'm
>> going to have multiple JPanels to organize the textfields. I want to
[quoted text clipped - 50 lines]
> return newImage;
> }
thanks, that worked great.