Forums Register Login

Working with Image Icon

+Pie Number of slices to send: Send
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 ?

+Pie Number of slices to send: Send
You may make a.jpg and b.jpg to have same size, this way would be easier than doing on coding.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
Don't listen to Steve. Just read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 4207 times.
Similar Threads
java swing repaint
Image in JFrame ???
GridBagLaout
Layout ,scrollbar problem
How do I display an image on a JLabel
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 05:59:21.