image thumbnail

Reorderable Listbox

version 1.9.0.0 (38.9 KB) by Erik Koopmans
Creates a listbox whose contents can be reordered by clicking and dragging items.

1.2K Downloads

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:
http://www.mathworks.com/matlabcentral/fileexchange/14317

Cite As

Erik Koopmans (2021). Reorderable Listbox (https://www.mathworks.com/matlabcentral/fileexchange/37642-reorderable-listbox), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2010a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!