I am using uicontrol to create GUI Elements. Following is my Code
uicontrol('Style','pushbutton', 'String','Load data','Parent',hTabs(1),'Position',[250 825 80 20], 'Callback',@ButtonCallback);
Here the problem is when i am using Units normalized option the GUI element is disappearing from Screen. I want to use normalized so that GUI adjusts itself in different screen resolutions. Any idea on this would be very helpful for me.
When you use Normalized units you need to define the position between 0 and 1, with 0 being the bottom/left hand side and 1 being the total height/width of the containing object.
You are currently defining the position using numbers that are well out of this range. You can do two things.
normalized in seperate function call (demonstrated below)uicontrol with normalized units, but you'll have to calculate the proper position vectorHere are examples on how to do either
A simple solution is to create the uicontrol and then set the units to normalized in a separate call
u = uicontrol(...) %don't specify the units
set(u,'Units', 'Normalized'); % this solves your problem
If you want to get the position vector in normalized units
normPos = get(u, 'Position') % get the position in normal space
Then use these numbers to create the uicontrol with normalized units:
u = uicontrol(...,'Units','Normalized', 'Position', normPos);
When using the 'units','normalized' option you must change your position vector. The figure reference system has coordinates between 0 and 1.
E.g.
uicontrol('Style','pushbutton',...
'String','Load data',...
'Parent',hTabs(1),...
'units','normalized',...
'Position',[0 0 0.1 0.1],...
'Callback',@ButtonCallback);
gives you a button 10% of the height and width in the lower left corner of the parent panel.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With