This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Hello friends , I am a learner in SWING .. i have a problem which i would hope that atleast someone wud have the solution for it .. "I am using a GRIDBAGLAYOUT and adding buttons and labels to a panel ..Its working fine but now i also wanna add an IMAGE to the panel .. how can i do that without using button or label as a container for image ?? please explaing with the code for it ?? " Hoping for an early response. saurabh
Success is not doing extraordinary things but doing ordinary things extraordinarily well.
There's no such thing as an IMAGE component... you *have* to use another component to display an image. You're not really specific about what you are trying to do, but if you need to load an image from a file, the easiest thing to do is load the image into an ImageIcon and then send it to a JLabel :
If you are trying to make some kind of dynamic image that the user has to interact with, then you would be better off making a custom component, using BufferedImage, etc. This is much more complicated...
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
As Nathan said you can add an image as a component and let the layout manager lay it out with the other components. The other general approach is to draw the image on the background of the panel that you are adding your components to — components then appear above the plane of the image.
[ March 11, 2004: Message edited by: Craig Wood ]
Joined: Oct 07, 2003
Hello NATHAN and CRAIG , Well thx for ur replies and it really helped me out .. i was actually implementing the thing as wat it was said by NATHAN ..so the conclusion is that we cant have image as a component and it needs a container like LABEL though label itsel fis a component ... Anyways thx again and hope u keep giving ur suggestions always , saurabh