Mostra commenti meno recenti
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 Commenti
Robert Cumming
il 19 Dic 2011
Is there any reason why you are not using the matlab commands set and get?
Aldin
il 19 Dic 2011
Risposta accettata
Più risposte (1)
Sean de Wolski
il 19 Dic 2011
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 Commenti
Aldin
il 19 Dic 2011
Aldin
il 19 Dic 2011
Sean de Wolski
il 19 Dic 2011
simple. I did it in both examples above. How did I extract the name from the list of names? What was the result of the first example when you selected an item and then got it's value as I did?
Aldin
il 19 Dic 2011
Aldin
il 19 Dic 2011
Aldin
il 19 Dic 2011
Categorie
Scopri di più su Call Java from MATLAB in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!