필터 지우기
필터 지우기

How use Pop-Up Menu with including Check Box?

조회 수: 41 (최근 30일)
Jun-Hyeong kim
Jun-Hyeong kim 2011년 10월 21일
댓글: Ganesh Naik 2021년 12월 16일
How use Pop-Up Menu with including Check Box?
I would like to use Pop-Up Menu with Check Box.
In general, When I check PopUp Menu, then show the List.
But, I'd like to make List in CheckBox Style
Please give me some solution or answer.

채택된 답변

Walter Roberson
Walter Roberson 2011년 10월 21일
A pop-up menu cannot include a check box (not unless perhaps you work at the Java level.)
You can have a push-button that turns on the visibility of a radiobutton group.
  댓글 수: 1
Jun-Hyeong kim
Jun-Hyeong kim 2011년 10월 21일
working java level means hard coding?
And if you have any example solution, could you provide it to me.

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

추가 답변 (3개)

Jan
Jan 2011년 10월 21일
You can use a uicontextmenu, which has built-in checkmarks. It can be enabled by a left mouse click on any other uicontrol, e.g. a button. The position of the uicontextmenu should be set relative to the button to let it look more as a popup menu:
FigH = figure;
PopH = uicontextmenu('Parent', FigH);
uimenu(PopH, 'Label', 'Unchecked');
uimenu(PopH, 'Label', 'Checked', 'Checked', 'on');
ButtonH = uicontrol('Style', 'PushButton', 'Position', [20, 300, 60, 22], ...
'String', 'Click me', ...
'UIContextMenu', PopH, ...
'Callback', {@showMyPopup, PopH});
function showMyPopup(ButtonH, EventData, PopH)
Pos = get(ButtonH, 'Position');
set(PopH, 'Position', [Pos(1)-2, Pos(2)-1], 'Visible', 'on');
Currently this is a pop- down menu. At least it need no calls to undocumented functions.

Daniel Pantea
Daniel Pantea 2020년 2월 6일
편집: Daniel Pantea 2020년 2월 6일
CheckBoxListComboBox.png
Simple example of "CheckBoxListComboBox" usage:
f = figure;
% create CheckBoxListComboBox
jCB = com.jidesoft.combobox.CheckBoxListComboBox({'Item-1', 'Item-2', 'Item-3', 'Item-4', 'Item-5', 'Item-6', 'Item-7', 'Item-8'});
[hJavaCB, hJavaCBWrapper] = javacomponent(jCB, [], f); %#ok
set(hJavaCBWrapper, ...
'Units', 'pixels', ...
'Position', [4,4,460,20]);
set(hJavaCB, ... % modify CB properties
'ToolTipText', ...
['<html>Supports <b>multiple</b> selections via <i><font color="red">drop-down</font></i> list + OK, or by editing directly (but ensure ' ...
'<br /> correct spelling and that there is exactly one semicolon followed by at least one space "; " between items)</html>'], ...
'Name', 'Display range' ...
);
% direct access
hJavaCB.setSelectedIndices([0,1,4]);
xx = hJavaCB.getSelectedIndices(); % xx = [0,1,4]
% indirect access via model
jModel = hJavaCB.getModel();
sz = jModel.getSize(); % sz = 8
jModel.getElementAt(0); % ans = 'Item-1'
xx = jModel.getSelectedItem(); % ans = java.lang.Object[]: 'Item-2'; 'Item-5'; 'Item-8'. Use numel(xx), strcmp(xx(1),'Item-2'), etc
jModel.getIndexOf('Item-2'); % ans = 1
jModel.insertElementAt('Item-99', 3); % inserts between 'Item-3' (on pos 2) and 'Item-4' (on pos 3)
jModel.addElement('Item-100'); % append to end
%jModel.removeAllElements();
jModel.removeElement('Item-1');
jModel.removeElementAt(3);
jModel.setSelectedItem(['Item-5';'Item-6';'Item-7']);
hJavaCB.setFocusable(true);
hJavaCB.putClientProperty('TabCycleParticipant', true); % this may be unnecessary in some cases, but doesn't hurt
set(hJavaCB, ...
... % handles keys like VK_LEFT, etc
'KeyPressedCallback', {@callback_javaKeyPress}, ...
... % handles any selection changes, even temporary ones, before OK or Cancel!
'PropertyChangeCallback', {@callback_javaPropertyChange}, ...
... % handles only final selection changes, after Enter, OK or Cancel...
'ActionPerformedCallback', {@callback_javaActionPerformed} ...
);
% 'KeyPressedCallback' from hJavaCB
function callback_javaKeyPress(h, event)
switch event.getKeyCode()
case event.VK_LEFT
character = 'left';
otherwise
character = event.getKeyChar();
end
% character, event
end % function callback_javaKeyPress
% 'PropertyChangeCallback' from hJavaCB
function callback_javaPropertyChange(h, e)
%disp(' callback_javaPropertyChange ');
%h, e
%list = h.getSelectedIndices(); % not the indices are 0-based, and -1 means invalid field
%fprintf(1, 'callback_javaPropertyChange: ');fprintf(1, ' %d', list); fprintf(1, '\n');
end % function callback_javaPropertyChange
% 'ActionPerformedCallback' from hJavaCB
function callback_javaActionPerformed(h, e)
list = h.getSelectedIndices(); % not the indices are 0-based, and -1 means invalid field
fprintf(1, 'callback_javaActionPerformed: ');fprintf(1, ' %d', list); fprintf(1, '\n');
h, e
end % function callback_javaActionPerformed
Tested with 2017a and 2020a ...
  댓글 수: 1
Ganesh Naik
Ganesh Naik 2021년 12월 16일
Hi Daniel thanks for this wonderful tool. While running the code using Matlab 2021a version it gave me the following warning:
Warning: JAVACOMPONENT will be removed in a future release. For more information see UI Alternatives for MATLAB Apps on mathworks.com.
> In javacomponent (line 85)
In Popup_Checkbox (line 4)
I tried to find the alterantive using the following website
Could you please let me know whether do I need to work with UIfigure instead?

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


amir soheil
amir soheil 2016년 1월 12일
checkboxcombo class in java programing is best...refer to undocument matlab website

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by