View License

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

» Watch video

Highlights from
Reorderable Listbox

4.8 | 4 ratings Rate this file 7 Downloads (last 30 days) File Size: 38.9 KB File ID: #37642 Version: 1.9
image thumbnail

Reorderable Listbox



27 Jul 2012 (Updated )

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

| Watch this File

File Information

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:


Findjobj Find Java Handles Of Matlab Graphic Objects inspired this file.

MATLAB release MATLAB 7.10 (R2010a)
Other requirements Java must be enabled.
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (6)
15 Dec 2015 Dev-iL

Dev-iL (view profile)

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

28 Jul 2014 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.

15 Aug 2013 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!

Comment only
15 Aug 2013 Soren Preus

Nice utility that works fine on my R2012b.

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

22 Oct 2012 Jonathan Lister

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

Comment only
22 Oct 2012 Jonathan Lister

30 Jul 2012 1.5

Modified description, documentation, and screenshot.

31 Jul 2012 1.7

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

31 Jul 2012 1.9

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

Contact us