Silly question, how to display a bitmap in a JDialog?

I know there should be somehow easy to do this, but I can't find the documentation that would let me add a graphic object in a dialog box and assign a bitmap file (either GIF or JPG).Any help will be apreciated, or a link to a web page that shows this.Thanks
[280 byte] By [RobertoZozayaa] at [2007-11-27 3:43:25]
# 1
I got it working using a JLabel and then using HTML code to put the image....But I would like to know if there is another way to doing the same thing.Thanks
RobertoZozayaa at 2007-7-12 8:47:04 > top of Java-index,Desktop,Core GUI APIs...
# 2

i think the easiest way to achieve this is use a JLabel with an icon displaying the bitmap. You should write an utility method to create the Icon:

public static ImageIcon createIcon(String iconName) {

URL iconURL = getResource(iconName);

if(iconURL == null) return null;

ImageIcon icon = new ImageIcon(iconURL);

if(icon == null || icon.getIconWidth() == -1) {

System.err.println("Failed to load '" + iconName);

}

return icon;

}

public static URL getResource(String resourceName) {

return Thread.currentThread().getContextClassLoader().getResource(resourceName);

}

Then you say:

JLabel label = new JLabel(createIcon("images/myIcon.gif"));

and all you have to do is place the label in the layout of your dialog.

HansBickela at 2007-7-12 8:47:04 > top of Java-index,Desktop,Core GUI APIs...