Using Image inside a Swing GUI
What is the 'correct' method for using images inside a Swing GUI?
Bascially I want to break this down into 2 questions:
1) How should they be stored, is it preferable to have the image hard-coded into code or as a seperate file?
2) How can you place them onscreen? At the moment I'm trying to do something as simple as making an "About" box with an image on the left and a bit of jLabel text on the right, however the image seems to get overlayed on top of everything else hence not obeying layout rules and covering up the text even though they are tied to different jPanels.
1) you should be able to store images in a jar (perhaps the same one your class files are in). I would google for information about that.
2) What about putting your image as the background of a JPanel, setting the panel's size, and placing the panel in the layout? There must be some existing about dialog box code in Sun's tutorials.
maybe you could read images in from your jar using java.util.jar.JarInputStream. Unless, of course, there is an even easier method of doing it.
How is it possible to set the background of a jPanel to an image? The setBackground method only takes a colour as an argument.
can you post your current code that overlays the text/image?
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center