Nico Huysamen
Nico Huysamen

Reputation: 10427

Drag and drop widgets in Java 2D

Is there any material/tutorials available that can shed some light on creating drap and drop widgets with Java 2D? I am not talking about drag and drop data transfer like here. What I want to do is have a visual pane in my application, where users can create widgets, connect them to each other etc. Something like a creating a graph, but with widgets that have properties.

Thanks.

Upvotes: 0

Views: 731

Answers (2)

Nico Huysamen
Nico Huysamen

Reputation: 10427

I have found the perfect solution. I can make use of the Netbeans Visual Library by extracting jar from the Netbeans Platform.

Upvotes: 0

bvk256
bvk256

Reputation: 1903

This is generally works like this:

  1. When a user presses the mouse button your application goes to a "drag" mode
  2. When repaint() method is called while you're in drag mode you move your widget position to the coordinates of the cursor
  3. When mouse button is released you fixate the ultimate position of the windget.

The simple illustration for this might be a program I was writing in my youth - interactive chess board. Here is relevant class that includes pieces dragging capabilities http://jinyan.svn.sourceforge.net/viewvc/jinyan/trunk/jinyan/client/src/net/sfficslecview/lvboard/EditableChessBoard.java?revision=77&view=markup

Upvotes: 1

Related Questions