File Exchange

image thumbnail

Copy Paste

version (36.2 KB) by Amitabh Verma
A simple Cut, Copy, Paste contextmenu for edit boxes in GUI.

1 Download

Updated 21 Jun 2010

View License

Copy Paste ver. 1.0

This is a very simple cut/copy/paste context menu using java handles. This code uses findjobj by Yair Altman ( to locate the java handles.



f1 = figure('Name','Copy-Paste','Position', [480 480 340 100],'NumberTitle','off');
h1 = uicontrol(f1, 'Style', 'edit',...
'String', 'Cut',...
'BackgroundColor', [1 1 1],...
'Position', [10 10 100 50]);
h2 = uicontrol(f1, 'Style', 'edit',...
'String', 'Copy',...
'BackgroundColor', [1 1 1],...
'Position', [120 10 100 50]);
h3 = uicontrol(f1, 'Style', 'edit',...
'String', 'Paste',...
'BackgroundColor', [1 1 1],...
'Position', [230 10 100 50]);

% For single edit box object

% For selected edit box object

% For all the edit boxes in a figure
copy_paste(gcf) or copy_paste(f1)

Your comments and suggestions are most welcomed.

Cite As

Amitabh Verma (2021). Copy Paste (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (1)

John Iversen

This is amazing! So simple, yet adds a critical missing function to edit boxes. Thank you!

I've made the following improvements and updates

1) handle multi-line edit text boxes by adding the following to javahandles.m (from the incredible Yair,

try %is it a multi-line text edit box?
jObject = handle(jEditbox.getViewport.getView, 'CallbackProperties');

2) added an option to open URL--can't make html links in an edit box unless the box is made inactive and not editable (per Yair). So this is a compromise: select the link and chose Open URL from the contextual menu. Add this line to copy_paste.m after the 'Select All' line.

uimenu(copypastemenu, 'Text', 'Open URL', 'Accelerator', 'O', MenuSelectedFcn', 'web(jObject.SelectedText, ''-new'', ''-browser'')');

(Note here also there are newer option names for adding shortcut keys and callback and the other lines need to be changed to match)

3) Finally, I prefer to have javahandles.m use findjobj_fast from Yair Altman, instead of findjobj.

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!