slider for scrolling in GUI

Hello! I have some problems with a slider that I am using for moving my objects on an interface.
This is what I am using:
pos1=get(handles.btn1,'Position');
pos2=get(handles.btn2,'Position');
pos3=get(handles.edittxt,'Position');
slider_value=get(hObject,'Value');
set(handles.btn1,'Position',[pos1(1) pos1(2)-slider_value+1 pos1(3) pos1(4)]);
set(handles.btn2,'Position',[pos2(1) pos2(2)-slider_value+1 pos2(3) pos2(4)]);
set(handles.edittxt,'Position',[pos3(1) pos3(2)-slider_value+1 pos3(3) pos3(4)]);
At this point I am blocked because I really don't know how to move the scroll bar up and down. I don't know how to make conditions... Please help!!!

2 件のコメント

Jan
Jan 2011 年 9 月 12 日
Please format your code. See: http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup
I do not understand the question. The scrollbar is moved by the mouse. And conditions are implemented by the IF statement. Please explain, what you want to achieve.
Diana Acreala
Diana Acreala 2011 年 9 月 13 日
Please see my last response to Walter Roberson. Thanks!

サインインしてコメントする。

回答 (1 件)

Walter Roberson
Walter Roberson 2011 年 9 月 12 日

0 投票

You would put code such as that in the callback for a slider.
I do not recommend that code. As noted in response to your earlier question, you should instead insert your elements in a uipanel and then set() the Position of the panel in your scroll callback: that will have the effect of moving everything contained within the uipanel all as a group.
If you want to position a slider to a particular location, you set() the value property of the slider.

4 件のコメント

Diana Acreala
Diana Acreala 2011 年 9 月 13 日
I would prefer to use this code. It's working, all the elements are moving. The problem is that I don't know how to make it work up and down. Now if I use ('pos1(2)-slider_value+1') it is moving only down(because of the minus) no matter what the slider arrow I am pressing. If I use ('pos1(2)+slider_value+1')it's moving only down, and the same thing, no matter what arrow of the slider I am pressing... I was thinking to put some conditions related to the maximum and minimum values.. but I don't know if it's correct because I don't really know what would be the correct limits.
My problem is that I have a big interface that can not be seen totally on small monitors.
Maybe you can give me another ideea, other then using this slider thing.
Walter Roberson
Walter Roberson 2011 年 9 月 13 日
Store the _original_ positions for each item, such as in the item's UserData property, and then apply the slider value relative to the _original_ position.
If you have a big interface that cannot be seen totally on small monitors, that is often a sign that you should be redesigning your interface, such as with pop-up controls or menu items that temporarily give access to a particular section of the interface and then hide it mostly away again afterwards.
If you are using a new enough version of MATLAB, using uitab() might be another possibility. I have, though, not yet noticed anything with the uitab() interface that is not essentially the same as having a series of uipanel() and choosing which panel you want to be visible.
Diana Acreala
Diana Acreala 2011 年 9 月 13 日
Oh...finally! It's working... I left aside the idea of using sliders. I found a solution and it was so simple.. http://www.mathworks.com/help/techdoc/creating_guis/f9-998364.html
I just put the Resize behaviour on Proportional and it's working just fine!
Thank you for your answers and for trying to help :D
Walter Roberson
Walter Roberson 2011 年 9 月 13 日
That corresponds to using "normalized" units in my prior discussion of your options, http://www.mathworks.com/matlabcentral/answers/15641-adopt-the-gui-window-to-my-computer-settings
As I noted then: some GUI elements (especially text) look very ugly if they are specified in "normalized" units

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeData Type Conversion についてさらに検索

質問済み:

2011 年 9 月 12 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by