BOMEz
BOMEz

Reputation: 1010

Select an image from JPanel

I am working on a small project which requires me to load images into a window and then move them around at will.

Thus far I can load images onto a JPanel simply by using a graphics object to draw them to the JPanel.

Now I'm faced with the challenge of figuring out how to differentiate between the various images I've loaded when I click on them so I can drag them around the screen.

Any ideas?

Upvotes: 0

Views: 371

Answers (2)

camickr
camickr

Reputation: 324088

Use the Component Mover to drag any component around the screen.

Upvotes: 0

Jason S
Jason S

Reputation: 189626

If you use a JLabel for each image, and make the JLabels subcomponents of the JPanel, it'll automatically draw the image, and you can add MouseListeners to each of them to be able to drag them around the screen.

Upvotes: 2

Related Questions