MATLAB: Connect two uicontrol object with a line

drawline()uicontrol

Hi,
I'm trying to get a nice and tidy GUI with a veriable number of uicontrol objects. To get a clean and clear layout I want to connect several objects with a simple line or path. Has anybody an idea how to implement this?
Thanks for your response, CN

Best Answer

You could use an invisible axes in the background and draw line objects. For example:
fig = figure('units','pix');
pos = get(fig,'position');
ax = axes('units','pix','outerposition',[0 0 pos([3 4])],...
'position',[0 0 pos([3 4])],'parent',fig,'visible','off','xlim',...
[0 pos(3)],'ylim',[0 pos(4)]);
h(3) = uicontrol('units','pix','position',[300 10 100 100],'style','push');
h(2) = uicontrol('units','pix','position',[10 10 100 100],'style','push');
h(1) = uicontrol('units','pix','position',[300 300 100 100],'style','push');
pos = get(h,'position');
for ii = 1:length(h)-1
line('xdata',[pos{ii}(1)+pos{ii}(3)/2, pos{ii+1}(1)+pos{ii}(3)/2],...
'ydata',[pos{ii}(2)+pos{ii}(4)/2, pos{ii+1}(2)+pos{ii}(4)/2],'parent',ax)
end