• Post Reply Bookmark Topic Watch Topic
  • New Topic

Drag and Drop where source and destination are the same.  RSS feed

 
David Garratt
Ranch Hand
Posts: 216
Eclipse IDE Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am wanting to create a application which has a flowchart/drawing type capability. If I have a simple swing frame with desktop pane and say a jbutton on it, would it be possible to move that button around by using the drag and drop functionality ? I don't want to move it to another container, just move it's x-y position using the mouse.

Thanks

Dave
 
David Garratt
Ranch Hand
Posts: 216
Eclipse IDE Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just answered my own question using this code :-

button.addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseDragged(MouseEvent e) {
button.setLocation(button.getX()+e.getX(),button.getY()+e.getY());
}
});

 
David Garratt
Ranch Hand
Posts: 216
Eclipse IDE Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I have a panel which contains checkbox's which I can now drag around my form - 1st stage complete. Each checkbox will either be visible or invisible depending on the value of "type" which I assign to the panel. It could be a process box, decision, action etc. Lets say for example I have a very simple scenario where my frame contains just 2 of the panels shown in the attachment. I want to draw a line from the "bottom" checkbox on one panel to the "upper" checkbox on another panel. I've not looked a java graphics yet, but I guess I can find an example with google. What I need to do somehow is register this line as some kind of object in it's own right with the 2 panels that it's linking. So when either one of them is moved using my mouse drag code it will remove and re-draw the line to reflect the new position. Any pointers about this extension to my code would be appreciated.

Thanks

Dave
2010-07-09_115144.gif
[Thumbnail for 2010-07-09_115144.gif]
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!