uisearchbox
Creates a search box in a container object.
Syntax
searchbox = uisearchbox()
searchbox = uisearchbox(property, value, ...)
searchbox = uisearchbox(parent, property, value, ...)
Inputs
- parent
- Handle of a container object, which could be a figure, uibuttongroup, uipanel or uipanel.
- property, value
-
- 'backgroundcolor'
- Specifies the background color. Valid values are 'transparent' or a real vector specifying RGB values in the range 0-255 or 0-1.
- 'createfcn'
- Function that is executed when searchbox is created. If value is a function handle, it must be a function that takes at least two arguments, the first being the handle, searchbox. The second argument is ignored. If value is a string, it must represent a function handle or a function name. If value is a cell, it must contain the function name/function handle in the first cell element and parameters to pass to the callback function in the additional elements.
- 'deletefcn'
- Function that is executed when searchbox is deleted. If value is a function handle, it must be a function that takes at least two arguments, the first being the handle, searchbox. The second argument is ignored. If value is a string, it must represent a function handle or a function name. If value is a cell, it must contain the function name/function handle in the first cell element and parameters to pass to the callback function in the additional elements.
- 'enable'
- Specifies if searchbox is enabled. Valid values are'on'(default) and 'off'.
- 'fontangle'
- Specifies angle of the displayed font. Valid values are 'regular'(default) and 'italic'.
- 'fontname'
- Specifies name of the displayed font.
- 'fontsize'
- Specifies size of the displayed font.
- 'fontunits'
- Determines if fontsize property is absolute or relative based on fontsize of the parent of searchbox. Valid values are 'pixels' (default) or 'normalized'.
- 'fontweight'
- Specifies weight of the displayed font. Valid values are 'normal' (default) and 'bold'.
- 'foregroundcolor'
- Specifies the color of matchpattern. Valid values are 'transparent' or a real vector specifying RGB values in the range 0-255 or 0-1.
- 'horizontalalignment'
- Specifies the horizontal alignment of the text in matchpattern. Valid values are left(default), right, center and justify.
- 'iconposition'
- Specifies the position of the search icon in searchbox. Valid values are leading(default) or trailing.
- 'matchcase'
- Specifies if case is matched during a search. Valid values are 'off'(default) and 'on'.
- 'matchpattern'
- The pattern used for the search. Results of the search will be contained in the read-only properties of matchpositions, which would contain the positions of the results, specified in matchvalues. Specifying the matchpattern will automatically trigger a search if there is a valid searchobj.
- 'parent'
- Specifies the parent.
- 'position'
- Position and size of searchbox. Value is specified as a vector of form: [left top width height]. If 'units' has a value of 'normalized', values must be between 0 to 1.
- 'searchobj'
- Specifies the handle of the object which is searched. Valid objects are of type uitable or uicontrol of styles listbox or popupmenu.
- 'syntax'
- Syntax of the search. Valid values are 'wildcard' (default), , a simple pattern matching syntax used by command shells or 'regexp', which uses the oml regexp command.
- 'tag'
- User-defined string to tag searchbox.
- 'tooltipstring'
- Tooltip to display.
- 'units'
- Specifies units of measurement. Valid values are 'pixels'(default) and 'normalized'. Value 'pixel' indicates that searchbox has a fixed size and position specified by 'position'. Value 'normalized' indicates that searchbox will be resized if parent is resized.
- 'userdata'
- User-defined numerical data.
- 'value'
- User-defined value.
- 'verticalalignment'
- Specifies the vertical alignment of the matchpattern displayed. Valid values are top, bottom and middle (default).
- 'visible'
- Specifies if searchbox is visible. Valid values are 'on'(default) and 'off'.
Outputs
- searchbox
- Handle of the uisearchbox.
Examples
Create a search box for a popupmenu with a case sensitive search:
function popupmenu_callback(handle, data, varargin)
printf('Executing callback, handle: [%f]\n', handle);
end
Dialog = figure();
popupmenu = uicontrol('parent', Dialog, 'style','popupmenu' ...
, 'callback','popupmenu_callback', 'units','normalized', 'position',[0.17 0.43 0.63 0.1] ...
, 'value', 1 , 'string', {'apple 1' 'orange 1' 'Orange 2' 'pear 1' 'pear 2' });
searchBox = uisearchbox('parent', Dialog ...
, 'units','normalized', 'position',[0.17 0.30 0.63 0.10] ...
, 'searchobj', popupmenu, 'matchcase', 'on', 'syntax', 'wildcard');
Create a search box for a table and get the matched results:
function uiTable_celleditcallback(handle, data, varargin)
printf('Executing celleditcallback, handle: [%f]\n', handle);
end
uiTable = uitable('parent', Dialog, 'celleditcallback','uiTable_celleditcallback' ...
, 'units','normalized', 'position',[0.10 0.13 0.64 0.38] ...
, 'enable','on', 'fontname','MS Shell Dlg', 'fontangle','regular', 'fontweight','normal', 'fontsize',8.58 , 'fontunits','pixels' ...
, 'data',{1,2,3;4,'foo',6;7,8,'str2';10,11,12} ...
, 'backgroundcolor',[255,255,255], 'columneditable',[], 'columnformat',{} ...
, 'columnwidth','auto', 'foregroundcolor',[20,20,20], 'interruptible','off' ...
, 'rowheight','auto', 'rowstriping','off', 'tag','uiTable' ...
, 'userdata',[], 'value',0, 'tooltipstring','', 'visible','on');
searchbox = uisearchbox('parent', Dialog ...
, 'units','normalized', 'position',[0.10 0.05 0.64 0.05] ...
, 'enable','on', 'fontname','MS Shell Dlg', 'fontangle','regular', 'fontweight','normal', 'fontsize',8.58 , 'fontunits','pixels' ...
, 'horizontalalignment','left' ...
, 'verticalalignment','middle', 'foregroundcolor', [20 20 20], 'backgroundcolor', [255 255 255] ...
, 'tag','searchbox', 'userdata',[], 'value',0, 'tooltipstring','', 'visible','on' ...
, 'matchcase', 'off', 'searchobj', uiTable, 'matchpattern', '1', 'syntax', 'wildcard');
pos = get(searchbox, 'matchpositions')
vals = get(searchbox, 'matchvalues')
pos =
{
[1,1] [Matrix] 1 x 2
1 1
[2,1] [Matrix] 1 x 2
4 1
[3,1] [Matrix] 1 x 2
4 2
[4,1] [Matrix] 1 x 2
4 3
}
vals =
{
[1,1] 1
[2,1] 10
[3,1] 11
[4,1] 12
}
Create a search box for a list box, with a regular expression search pattern:
function listBox_callback(handle, data, varargin)
printf('Executing callback, handle: [%f]\n', handle);
end
Dialog = figure('units', 'pixels', 'position', [0 0 410 310] ...
, 'name','Dialog', 'windowicon','', 'windowstyle','docked' ...
, 'tag','Dialog', 'handlevisibility','on', 'numbertitle','off', 'visible','on');
listBox = uicontrol('parent', Dialog, 'style','listbox' ...
, 'callback','listBox_callback', 'units','normalized', 'position',[0.17 0.43 0.63 0.34] ...
, 'enable','on', 'fontname','MS Shell Dlg', 'fontangle','regular', 'fontweight','normal', 'fontsize',8.58 , 'fontunits','pixels' ...
, 'value', 1 , 'string', {'apple 1' 'orange 1' 'orange 2' 'pear 1' 'pear 2' 'File021.prn', 'File0.PRN' } ...
, 'foregroundcolor', [20 20 20], 'backgroundcolor', [255 255 255] ...
, 'interruptible','off', 'max',1, 'min',0 ...
, 'tag','listBox', 'userdata',[], 'value',0, 'tooltipstring','', 'visible','on');
searchBox = uisearchbox('parent', Dialog ...
, 'units','normalized', 'position',[0.17 0.30 0.63 0.10] ...
, 'enable','on', 'fontname','MS Shell Dlg', 'fontangle','regular', 'fontweight','normal', 'fontsize',8.58 , 'fontunits','pixels' ...
, 'searchobj', listBox, 'tag','edit', 'userdata',[], 'horizontalalignment','left' ...
, 'verticalalignment','middle', 'foregroundcolor', [20 20 20], 'backgroundcolor', [255 255 255] ...
, 'value',0, 'tooltipstring','', 'visible','on', 'matchpattern', '.PRN' ...
, 'syntax', 'regexp', 'matchcase', 'off');
positions = get(searchBox, 'matchpositions')
values = get(searchBox, 'matchvalues')
positions = [Matrix] 2 x 1
6
7
values =
{
[1,1] File021.prn
[2,1] File0.PRN
}