Help with Custom UIControl Objects

조회 수: 2 (최근 30일)
Paul
Paul 2014년 3월 3일
댓글: Paul 2014년 3월 4일
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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

답변 (1개)

Image Analyst
Image Analyst 2014년 3월 4일
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
Paul
Paul 2014년 3월 4일
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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Call Java from MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by