GUI listbox

조회 수: 3 (최근 30일)
Aldin
Aldin 2011년 12월 19일
I try to get selected value(string) from listbox in MATLAB.
Is this code OK?? Here is my code:
mousePos = java.awt.Point(jEventData.getX, jEventData.getY);
clickedIndex = jListbox.locationToIndex(mousePos) + 1;
listValues = get(hListbox,'string');
clickedValue = listValues{clickedIndex};
msgbox(clickedValue);
How to use JAVA in matlab we have in java jList.getSelectedIndex();
  댓글 수: 2
Robert Cumming
Robert Cumming 2011년 12월 19일
Is there any reason why you are not using the matlab commands set and get?
Aldin
Aldin 2011년 12월 19일
Java is easier than MATLAB in JAVA we have method:
jList.getSelectedIndex(); jList.getSelectedValeu();
but in MATLAB we have not

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

채택된 답변

Walter Roberson
Walter Roberson 2011년 12월 19일
strings = get(hObject, 'string');
curval = get(hObject, 'value');
if iscell(strings)
curstring = strings{curval};
else
curstring = strings(curval, :); %char array
end
Whether the string parameter is a cell array of strings, or a char array, depends on exactly how the listbox was initialized. If it was initialized to a single string that did not have any '|' characters, or initialized to a char array, then a char array will be the result, but if it was initialized to a cell array of strings, or to a single string that had on or more '|' characters, then a cell array will be the result.
  댓글 수: 5
Aldin
Aldin 2011년 12월 19일
Is this possible with uitable????
Walter Roberson
Walter Roberson 2011년 12월 19일
Yes, see my response to your newer question on this topic.

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

추가 답변 (1개)

Sean de Wolski
Sean de Wolski 2011년 12월 19일
No reason to access java directly. Use get() with the handle to the listbox to recieve the value property. E.g:
figure; %new fig
h = uicontrol('units','norm','style','listbox',...
'string',{'hello';'world';'eww monday'},'position',[.2 .2 .4 .4]); %a listbox
Select 'world'.
Now at the command line:
get(h,'value')
Addendum:
So:
figure;
names = {'Aldin';'Sean';'John'};
h = uicontrol('units','norm','style','listbox',...
'string',names,'position',[.2 .2 .4 .4]);
h(2) = uicontrol('style','push','callback',@(src,evt)disp(names{get(h(1),'value')}));
Select my name then push the button
  댓글 수: 6
Aldin
Aldin 2011년 12월 19일
It's confused for me
Aldin
Aldin 2011년 12월 19일
I'm beginner in MATLAB

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

카테고리

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