1

I'd like to create an own displayable image in Java - this is not the problem. But this image should be draggable inside a JLabel (only within the JLabel).

First I plan to create a new class for this intention extended from class JComponent. With this I can use createImage(ImageProducer producer) to create my image. But how can I use this method?

Or is there another possibility to implement a draggable image?

skaffman
  • 398,947
  • 96
  • 818
  • 769
Laurenz
  • 110
  • 3
  • 13

1 Answers1

1

So the JLabel and its image can move on mouseDragged? You could do this with a JLayeredPane, and by adding a MouseListener to the JLabel or the layered pane. For example: dragging-a-jlabel-around-the-screen

Community
  • 1
  • 1
Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
  • Thanks, but I solved it in a different way... First I added a JLabel with an ImageIcon to a JPanel. Then I added a mousListener to the JLabel to get and set bounds of it while dragging. That's all I needed. – Laurenz Mar 13 '11 at 11:07