Forums Register Login

How to include a jpg in a Graphic

+Pie Number of slices to send: Send
Hey!
I have a big problem.
I started some weeks ago with swing and now I dont know how I can include a jpg in a Graphic.
Here what I allready have:



but the jpg is in another window and not in the same.
Thanks4 your help
1
+Pie Number of slices to send: Send
> Here what I allready have:

delete it and start again - never create a JFrame inside paint()
(and paint() should not be used - override paintComponent() in Swing)
+Pie Number of slices to send: Send
You've already created an ImageIcon. You can retrieve an Image from it. That Image can be drawn on the Graphics object.

Note however that you shouldn't load the ImageIcon each time paint or paintComponent is invoked. This could occur many times a second, and you don't want all that I/O all the time. You should create the ImageIcon in the constructor and assign it (or its Image) to an instance field, and use that instance field when painting.
His brain is the size of a cherry pit! About the size of this ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 956 times.
Similar Threads
java swing repaint
Image in JFrame ???
GUI Labels and Buttons
Working with Image Icon
how to paint some shape over another JComponent
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 10:24:25.