-
Using Image inside a Swing GUI
Hi guys,
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.
Cheers.
-
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?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks