This week's giveaway is in the Testing forum.
We're giving away four copies of TDD for a Shopping Website LiveProject and have Steven Solomon on-line!
See this thread for details.
Win a copy of TDD for a Shopping Website LiveProject this week in the Testing 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:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Working with Image Icon

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!

I have a JLabel such as
JLabel imageLabel = new JLabel(new ImageIcon("a.jpg"));

After clicking some button I want to load another image as "b.jpg" only at specific location of imageLabel(i.e on the center of image "a.jpg").

Is it possible. If yes, then how ?

 
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You may make a.jpg and b.jpg to have same size, this way would be easier than doing on coding.
 
P Jain
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!

No, I have already set a Image "a.jpg" as ImageIcon to a JLabel, that is bigger image. I want that when I clicks on some button,another image of smaller size will load on the center of "a.jpg" image.
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
P Jain
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!
Thanks its working.

But I have another problem, I am having a JPanel in which I have added a ImageLabel (which have a ImageIcon say "a.jpg") on a button click I am saving a image with same name "a.jpg" but the image on the Label and then Panel remain same (the previous one).

I want that when I click on some button, the image of ImageIcon gets change.

Initially I am having

Label_Image_Center =new JLabel(new ImageIcon("h3.jpg"));
Panel_Image.add(Label_Image_Center, new XYConstraints(19, 65, 123,141));

after clicking on button different images saves as "h3.jpg". Now, I am doing

Label_Image_Center.setIcon(new ImageIcon("h3.jpg"));
Panel_Image.add(Label_Image_Center, new XYConstraints(19, 65, 123,141));

but the image gets not change while when I open it(image) outside it show different image.
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are two ways you can do this. One way is to make up a new JLabel with a new ImageIcon with the next image you want to show, remove the existing JLabel from the gui and add the new JLabel. The other way is demonstrated below.
 
P Jain
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!
Thanks for your prompt reply...............
I am working on Cell Phone,I am getting Phone Screen image but in PPM (Portable Pixmaps) format, then I am converting it into JPG then resizing it into smaller size and then try to set it as a ImageIcon,so that each time whenever screen of Phone changes that ImageIcon on the Label also gets change.
But the method I am apply taking so much time,is there any method in which I will take less time.
 
Hey, sticks and stones baby. And maybe a wee mention of my stuff:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic