File Exchange

image thumbnail

Reorderable Listbox

version 1.9 (38.9 KB) by

Creates a listbox whose contents can be reordered by clicking and dragging items.



View License

Creates a listbox whose contents can be reordered by clicking and dragging items. The resulting listbox can be fully customized using standard GET and SET methods.

The listbox created is a standard Matlab UICONTROL('Style','Listbox'), whose underlying Java JList has the following properties modified: 'DragEnabled', 'DragSelectionEnabled', 'DropMode', 'DropTarget', 'MousePressedCallback', and 'MouseReleasedCallback'.

The user may specify their own 'MousePressedCallback' (JList), 'MouseReleasedCallback' (JList), 'DragOverCallback' (DropTarget), and 'DropCallback' (DropTarget) in the list of input property/value pairs. These callbacks will be called at the end of the REORDERABLELISTBOX default callbacks, with two inputs, HANDLE and EVENTDATA. The 'DragOverCallback' is given a third input, PERMORDER, which indicates how the list has been reordered, i.e. STRING = STRING(PERMORDER). This can be used to reorder any underlying data that the list may represent.

To reorder items, REORDERABLELISTBOX creates a drag-and-drop object tied to the listbox. An unintended result is that list items can be dragged off of the list and dropped onto other components. Items can also be dragged from other objects onto the list; dropping onto the list has no effect.

If the listbox displays erratic redraw behaviour when being reordered rapidly (single cells being drawn too tall or too wide), you may need to explicitly set the 'FixedCellHeight' and 'FixedCellWidth' properties of JLISTBOX (values of -1 tell Java to automatically determine cell size, but may lead to this erratic behaviour).

This utility makes use of the freely available FINDJOBJ, written by Yair Altman and available on the Matlab File Exchange:

Comments and Ratings (6)


Dev-iL (view profile)

This also works with hg2 (tested on R2015b). @ClaytonChu - could you upload the class version somewhere?

Clayton Chu

Nice utility! Would be better if I could set the callbacks outside of the constructor. I modified this slightly to make it a class to do that and it works quite nicely.

Erik Koopmans

Hi Soren, thanks! DND between listboxes would be useful - I'll look into it.

It would technically be possible with the current version of this function, by specifying your own DropCallback as an input (one that inserts the eventData.Transferable data into the list at the cursor location, if the source DropTarget is not the same as the destination). But you would run into at least one bug - the reorderableListbox still thinks it's in 'reorder' mode if you drop on something other than the listbox itself. With DND between listboxes, you'd be bound to run into this problem, and you'd be reordering the list you're trying to drop onto.

Earlier I decided this was an acceptable bug in reorderableListbox, but it would be nice to fix it anyway. In the process I'll try to build in the DND behaviour too. No promises that it'll happen soon, but I'll see what I can do!

Soren Preus

Nice utility that works fine on my R2012b.

Is there any way to implement drag'n drop in between different listboxes?

works great. enables drag and drop to other applications as well.



1.1.1: Separated DropCallback from MouseReleasedCallback, for more user customization.


1.1.0: Added support for user-definable callbacks (MousePressed, MouseReleased, DragOver); added permOrder.


Modified description, documentation, and screenshot.

MATLAB Release
MATLAB 7.10 (R2010a)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video