Reorderable Listbox

Creates a listbox whose contents can be reordered by clicking and dragging items.
Updated 31 Jul 2012

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:

Cite As

Erik Koopmans (2024). Reorderable Listbox (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2010a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Find more on Migrate GUIDE Apps in Help Center and MATLAB Answers

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes

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.