Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Image problem in SWING

 
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Saurabh Agrawal
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic