Help with Custom UIControl Objects

2 views (last 30 days)
Paul
Paul on 3 Mar 2014
Commented: Paul on 4 Mar 2014
Hi, I'm hoping to make a few custom UIControl objects. The internet has pointed me towards java. I have zero experience with java but I've made a few modest gains. Hopefully someone can help me in the right direction for what comes next.
Below is example code for a custom slider. It looks different. It has labels. It executes a callback function. Great.
What's wrong?
1) Some of the labels are showing up as '...'
1.s) Setting f to 1000 will fix this. Not elegant. Anyone know how to adjust sizing?
2) I would like to be able to change coloring.
3) This is minor but the callback is being called 3 times when I select a new position. I can live with that but I'd rather not. Ideas?
These should be straightforward so I'd really appreciate non-File Exchange replies.
Paul
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function Customslider
hFig = figure;
[j h] = javacomponent('javax.swing.JSlider');
set(h,'Parent',hFig)
temp_units = get(h,'Units');
set(h,'Units','normalized','Position',[0.1 0.1 0.1 0.8])
set(h,'Units',temp_units)
initPos = 4;
f = 10;
setMinimum(j, f );
setMaximum(j, 1.9*f );
setValue(j, f+(f/10)*(initPos-1) );
j.setMajorTickSpacing( f/10 );
j.setPaintLabels(true);
j.setPaintTicks(true);
j.setOrientation(1);
j.setSnapToTicks(1)
labels = {'0.5','6','12','30','38','51','68','87','100','130'};
lt =get(j, 'LabelTable');
for i=1:10
key = java.lang.Integer( f+f/10*(i-1) );
val = lt.get(key);
val.setText(labels{i});
lt.put(key, val);
end
set(j, 'LabelTable', lt);
set(j,'StateChangedCallback',@mycallback)
function mycallback(src,eventdata)
getValue(src)
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Answers (1)

Image Analyst
Image Analyst on 4 Mar 2014
I don't know the answer to your question. I just wanted to say that for anything unusual, tricky, fancy, or undocumented, especially GUI bells and whistles, I look to Yair's site: http://undocumentedmatlab.com/ Maybe you could too.
  1 Comment
Paul
Paul on 4 Mar 2014
Indeed that is one of the first places I browsed. Unfortunately quite a bit of the custom GUI pieces relate to using his code on the File Exchange, which means I don't actually learn what is going on. I'll have a second pass through later today and maybe I'll find something.
Thanks for reply,
Paul

Sign in to comment.

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!