*
The moose likes Swing / AWT / SWT and the fly likes Working with Image Icon Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Working with Image Icon" Watch "Working with Image Icon" New topic
Author

Working with Image Icon

P Jain
Ranch Hand

Joined: Jul 31, 2004
Posts: 52
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 ?



Regards<br />P Jain
Pat Hays
Ranch Hand

Joined: Aug 20, 2004
Posts: 138
You may make a.jpg and b.jpg to have same size, this way would be easier than doing on coding.


Download Java GUI Builder, <a href="http://www.mars3000.com" target="_blank" rel="nofollow">http://www.mars3000.com</a>
P Jain
Ranch Hand

Joined: Jul 31, 2004
Posts: 52
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

Joined: Jan 14, 2004
Posts: 1535
P Jain
Ranch Hand

Joined: Jul 31, 2004
Posts: 52
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

Joined: Jan 14, 2004
Posts: 1535
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

Joined: Jul 31, 2004
Posts: 52
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.
 
 
subject: Working with Image Icon
 
Similar Threads
Image in JFrame ???
java swing repaint
GridBagLaout
How do I display an image on a JLabel
Layout ,scrollbar problem