Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Working with Image Icon

 
P Jain
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • 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 ?

 
Pat Hays
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Craig Wood
Ranch Hand
Pie
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
P Jain
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • 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
Pie
Posts: 1535
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic