UISplitPane - Split a container (figure/frame/uipan​el) into two resizable sub-containers

Split a container (figure/frame/uipanel) into two resizable sub-containers, like Java's JSplitPane
6.2K Downloads
Updated 14 Jan 2015

View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

Syntax:
[h1,h2,hDivider] = uisplitpane(hParent,'propName',propVal,...)

Description:
UISPLITPANE splits the specified container(s) (figure, panel or frame, referenced by handle(s) hParent) into two distinct panes (panels) separated by a movable divider. If no hParent container is specified, then the current figure (gcf) is assumed. Matlab components may freely be added to each of the panes. Pane sizes may be modified by dragging or programmatically repositioning the movable divider.
UISPLITPANE returns the handles to the left/bottom sub-container h1, right/top sub-container h2, and the split-pane divider hDivider. If a vector of several hParents was specified, then h1,h2 & hDivider will be corresponding vectors in the containing hParents. If the hParents are found to be non-unique, then the returned handles will correspond to the unique sorted vector of hParents, so that no hParent will be split more than once.

The UISPLITPANE divider can be dragged to either side, up to the specified DividerMinLocation to DividerMaxLocation property values (defaults: 0.1 and 0.9 respectively, meaning between 10-90% of range). In Matlab 7+, additional one-click buttons are added to the divider, which enable easy flushing of the divider to either side, regardless of DividerMinLocation & DividerMaxLocation property values.

Several case-insensitive properties may be specified as P-V pairs:
- 'Orientation': 'horizontal' (default) or 'vertical'
- 'Parent': Handle(s) of containing figure/panel/frame
- 'DividerWidth': Divider width (1-25 [pixels], default=5)
- 'DividerColor': Divider color (default=figure background color)
- 'DividerLocation': Divider normalized initial location (.001-.999, default=0.5)
- 'DividerMinLocation': Normalized minimal left/bottom pane size (0-1, default=0.1)
- 'DividerMaxLocation': Normalized maximal left/bottom pane size (0-1, default=0.9)

hDivider is a standard Matlab object handle possessing all these additional properties. All these properties are gettable/settable via the hDivider handle, except for the 'Orientation' & 'Parent' properties which become read-only after the UISPLITPANE is constructed. hDivider also exposes the following read-only properties:
- 'LeftOrBottomPaneHandle': h1 value returned by this function
- 'RightOrTopPaneHandle': h2 value returned by this function
- 'DividerHandle': the HG container handle (a numeric value)
- 'JavaComponent': handle to the underlying java divider obj
- 'ContainerParentHandle': handle to hParent container
Note: this is important in Matlab 6 which does
^^^^ not allow hierarchical UI containers
- 'ContainerParentVarName': hParent variable name if available

Example:
[hDown,hUp,hDiv1]=uisplitpane(gcf,'Orientation','ver','dividercolor',[0,1,0]);
[hLeft,hRight,hDiv2]=uisplitpane(hDown,'dividercolor','r','dividerwidth',3);
t=0:.1:10;
hax1=axes('Parent',hUp); plot(t,sin(t));
hax2=axes('parent',hLeft); plot(t,cos(t));
hax3=axes('parent',hRight); plot(t,tan(t));
hDiv1.DividerLocation = 0.75; % one way to modify divider...
set(hDiv2,'DividerColor','red'); % ...and this is another way...

Technical description:
http://UndocumentedMatlab.com/blog/uisplitpane

Bugs and suggestions:
Please send to Yair Altman (altmany at gmail dot com)

Warning:
This code heavily relies on undocumented and unsupported Matlab functionality. It works on Matlab 6+, but use at your own risk!

Cite As

Yair Altman (2024). UISplitPane - Split a container (figure/frame/uipanel) into two resizable sub-containers (https://www.mathworks.com/matlabcentral/fileexchange/23073-uisplitpane-split-a-container-figure-frame-uipanel-into-two-resizable-sub-containers), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R12
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
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.4.0.0

Fixes for HG2 (R2014b); improved mouse-movement performance (responsivity)

1.3.0.0

Fixed some HG-Java warnings; fixed the panels' default bgcolor to be the same as their parent's bgcolor; fixed divider's arrow buttons bgcolor; fixed divider size upon dragging (panel resize); fixed minor Java issues with the divider sub-component

1.2.0.0

Fixed DividerColor parent's color based on Co Melissant's suggestion; re-fixed JavaFrame warning

1.1.0.0

Fix for R2008b JavaFrame warning

1.0.0.0