Help with Custom UIControl Objects
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0 commentaires
Réponses (1)
Image Analyst
le 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.
Voir également
Catégories
En savoir plus sur Interactive Control and Callbacks dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!