I've been looking around for a way to do this. I found some code to change the order of strings in a list, but i want to add buttons and such on each panel so that wouldn't work...
Asked
Active
Viewed 880 times
1
-
Layouts and drag-and-drop are two orthogonal concepts. You need to find a layout that allows you to order components, such as the GridLayout, and you need to implement your drag-and-drop separately. – Hovercraft Full Of Eels Mar 24 '12 at 18:22
2 Answers
4
You may want to take a look at the docking frameworks. For example, Docking Frames has a good example of a chess board - basically, you can "dock" pieces on the chess board squares which server as the drop targets. Just launch the demonstration via the provided jnlp and then pick the Chess demonstration in the list on the left to see how it works. Here's a screenshoot of it:
You can see that each of the squares is a docking tile (i.e. a draggable object).
In your case, instead of 8x8 of squares, you can have Nx1 to simulate a one-column list instead of a table.

icyrock.com
- 27,952
- 4
- 66
- 85
1
Use a JList
. Look into the dragging behavior for the reordering ability.
See How to Use Lists for more details.

Andrew Thompson
- 168,117
- 40
- 217
- 433
-
I tried to use JList, but to my knowledge, it can only be used for string. – arrow Mar 24 '12 at 19:10
-
1That is wrong. In recent times in posts to SO, I've used lists for [`Image`](http://stackoverflow.com/a/9544652/418556) and `Font` objects. – Andrew Thompson Mar 24 '12 at 19:23
-
2Use a custom renderer in your list, and you can display anything you want. – Sam Barnum Mar 24 '12 at 20:02