0

Possible Duplicate:
how to drag object

I need to draw some UML components (classes, packages etc) using Java 2D and then be able to drag them around. Is there a way to do this? I mean, to make a shape "draggable"?

Community
  • 1
  • 1
  • Are you looking for a [UML modeling tool](http://en.wikipedia.org/wiki/List_of_Unified_Modeling_Language_tools)or a basic [object-drawing example](http://stackoverflow.com/a/11944233/230513). – trashgod Dec 22 '12 at 12:00
  • Yes, there is a way to drag objects around using Java 2D. Could you share with us [what you've tried so far?](http://whathaveyoutried.com) – Makoto Dec 22 '12 at 15:26

3 Answers3

4

JHotDraw was designed as "a Java GUI framework for technical and structured Graphics." The linked JHotDraw Pattern Language: JHotDraw Domain Overview illustrates how to customize drawing editors. The sample org.jhotdraw.samples.draw.Main is a reasonable starting point, and JModeller is a simple UML editor built using the framework.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
0

Are you forced to swing?

If not you might have look at draw2d which is a java library that works on a SWT canvas. You can find some examples of draw2d here.

micha
  • 47,774
  • 16
  • 73
  • 80
0

You can only add MouseListener to a (J)Component. All Java2D stuff is painted on the component. If you manage all shapes in a List you can search for the correct shape under the mouse courser, move it and repaint the component.

Hendrik Ebbers
  • 2,570
  • 19
  • 34