Display checkbox inside a listbox

北慕城南 提交于 2019-12-25 12:21:07

问题


In my (programmatic) Matlab GUI, I have a listbox uicontrol.

What I want is to display checkboxes in front of each option. When a user clicks the checkbox, it's marked (and the element will be considered during the calculations later). While if the user clicks the label, a description of the selected option will be displayed in a text uicontrol to inform the user what the option means.

Basically, I want functionality similar to installation programs where you can select components to install and can get information about said components by clicking them (which does not necessarily mark them as selected).

Is there a way to do this with checkboxes or something similar?


回答1:


There's no "ready" way for doing that - as listboxes take only plain strings as entries.

You could "manually" draw checkbox fitted into the area of the listbox, but that might mean quite a lot of work to get everything working... Another alternative is to go for a java-componenent - e.g. using the jide components available in matlab. See e.g.

http://undocumentedmatlab.com/blog/using-jide-combo-boxes/

for a few examples.




回答2:


There are actually 2 built-in controls that you could use within Matlab:

  1. com.jidesoft.swing.CheckboxList
  2. com.mathworks.mwswing.checkboxlist.CheckBoxList

Usage example (more details in my Matlab-Java book):

jList = java.util.ArrayList; % any java.util.List will be ok jList.add(0,'First'); jList.add(1,'Second'); jList.add(2,'Third'); jList.add(3,'and last'); jCBList = com.mathworks.mwswing.checkboxlist.CheckBoxList(jList); jScrollPane = com.mathworks.mwswing.MJScrollPane(jCBList); [jhCBList,hContainer] = javacomponent(jScrollPane,[10,10,80,65],gcf); set(jCBList, 'ValueChangedCallback', @myMatlabCallbackFcn); jCBModel = jCBList.getCheckModel; jCBModel.checkAll; jCBModel.uncheckIndex(1); jCBModel.uncheckIndex(3);



来源:https://stackoverflow.com/questions/21437732/display-checkbox-inside-a-listbox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!