简体   繁体   English

当Min = Max = Value = 1时的Matlab滑块

[英]Matlab slider when Min=Max=Value=1

I use a slider to browse through a collection whose size changes dynamically and can very well be 1. 我使用滑块浏览一个集合,该集合的大小会动态变化,并且很可能为1。

But if I: 但是如果我:

set(mySld, 'min', 1, 'max', 1, 'value', 1, 'sliderstep', [1 1])

The slider will look like this, with the so-called thumb half as long as the "trough": 滑块看起来像这样,所谓的拇指只有“槽”的一半:

错误的滑块

Which is not okay, because if you then click on the left side of the slider, the value will be set to zero, ie out of range, and the slider simply disappears. 这不行,因为如果您然后单击滑块的左侧,则该值将设置为零,即超出范围,并且滑块会消失。

Am I using wrong property settings? 我是否使用了错误的属性设置?

(of course, I could set(mySld, 'enable', 'off') whenever Min=Max=1, but it feels like a hack). (当然,每当Min = Max = 1时,我都可以set(mySld, 'enable', 'off') ,但感觉就像是被黑客入侵了)。

You can use a listener to check for the value against the min and/or max: 您可以使用侦听器根据最小值和/或最大值来检查值:

figure; 
% create the uicontrol
sl = uicontrol ( 'style', 'slider', 'min', 1, 'max', 1, 'value', 1, 'sliderstep', [1 1]);
% create a listener to check the value are reset appropriately
addlistener ( sl, 'Value', 'PostSet', @(obj,event)set ( sl, 'Value', max(sl.Min,  min(sl.Value,sl.Max))) );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM