MATLAB Answers

Two knob slider for a GUI or app

96 ビュー (過去 30 日間)
Raptrick 2018 年 1 月 26 日
回答済み: Marek Svoboda 2020 年 2 月 10 日
For sorting out timing events I need a slider with two knobs, see picture taken from internet. Anyone a suggestion or a trick how implement this (UIspace) efficient in a matlab UI or App. Now it is implemented with two sliders: one for the min value and one for the max value. This is not so space efficient when you need of 10 these slider pairs.
  1 件のコメント
Adam 2018 年 1 月 26 日
If you want to go a little 'off-piste', you can use a Java range slider as detailed in Yair Altman's blog post:
I have used these a few times. I created a class to handle it, but you can just put the raw code in for single usage easily enough.



Raptrick 2018 年 1 月 28 日
Thanks Adam and Peter for your suggestions. I build the following code, had some troubles to find the position properties of the RangeSlider. So this is what I need...
function tryoutrangeslider2
Labels = {'January','February','March','April','May'};
Mins = [1 1 1 1 1];
Maxs = [31 28 31 30 31];
hF = figure;
for i=1:length(Labels)
% more direct instantiation
% jRS = com.jidesoft.swing.RangeSlider(0,100,20,70); %min,max,low,high
% [jRangeSlider{i}, hRangeSlider{i}] = javacomponent(jRS,[0,0,200,80],hF);%posx,posy,width,height
jRS = com.jidesoft.swing.RangeSlider;
[jRangeSlider{i}, hRangeSlider{i}] = javacomponent(jRS,[],hF);
% modify rangeslider position
% modify range slider properties
'MinorTickSpacing',1, ...
'PaintLabels',true, ...
% add text label
function jRangeSlider_Callback(jRangeSlider,event,i)
disp([jRangeSlider.Name ' ,extra parameter =' num2str(i)])
  1 件のコメント
Royi Avital
Royi Avital 2018 年 7 月 27 日
Is there a way to create 3 knobs slider like that?


その他の回答 (2 件)

Peter Cook
Peter Cook 2018 年 1 月 26 日
編集済み: Peter Cook 2018 年 1 月 26 日
I have dabbled with this a couple times myself. As Adam mentioned, you could use a range slider, but what if you want multiple thumbs? You've got options.
1. Use multiple thumbs. Here's an example I sandboxed awhile back:
hFig1 = figure('pos',[64,64,768,128]);
hFig1.ToolBar = 'none';
hFig1.MenuBar = 'none';
hFig1.Name = 'Select Frequency Range(s) in Hz';
hFig1.NumberTitle = 'off';
sliderWidth = 32;
for k = 1:20
jSlider{k} = javax.swing.JSlider;
sliderMin = 2*(k-1);
sliderValue = 2*k-1;
sliderMax = 2*k;
hjSlider{k} = handle(jSlider{k},'CallbackProperties');
hjSlider{k}.StateChangedCallback = @(hjSlider,eventData) disp(get(hjSlider,'Value'));
labelTable = java.util.Hashtable();
sliderValueLabel = sprintf('<html>10<sup>%0.1f</sup></html>',sliderValue/10);
jLabel = javax.swing.JLabel(sliderValueLabel);
labelTable.put(int32(sliderValue), jLabel);
jSlider{k}.setLabelTable( labelTable );
2. If you're savvy at programming & whatnot, you could extend this object (colormapeditor) to suit your needs:
3. Do a github search for for a pre-built class that does this.
  1 件のコメント
Royi Avital
Royi Avital 2018 年 7 月 27 日
Your code creates multiple sliders not one with multiple knobs.


Marek Svoboda
Marek Svoboda 2020 年 2 月 10 日
If you are trying to implement this in App Designer (which doesn't support Java), see my answer to a similar question.


Community Treasure Hunt

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

Start Hunting!

Translated by