How can I put a javacomponent in the app designer?

조회 수: 15 (최근 30일)
Mehmet Seker
Mehmet Seker 2018년 4월 22일
댓글: Yair Altman 2020년 4월 12일
In app designer, I tried to put checkbox created by 'com.jidesoft.swing.CheckBoxList'. but I can not settle it on app.UIFigure.
The code is
classdef test < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
end
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
items = {'1','2','3','4','5','6','7','8','9'};
jCBList = com.jidesoft.swing.CheckBoxList;
jCBList.setModel(javax.swing.DefaultListModel);
jCBList.setSelectionMode(0);
jScrollPane = com.mathworks.mwswing.MJScrollPane(jCBList);
javacomponent(jScrollPane, [50,200,100,100], app.UIFigure);
for i=1:size(items,2)
jCBList.getModel.addElement(items{1,i});
end
end
end
% App initialization and construction
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure
app.UIFigure = uifigure;
app.UIFigure.Position = [100 100 640 480];
app.UIFigure.Name = 'UI Figure';
end
end
methods (Access = public)
% Construct app
function app = test
% Create and configure components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
% Execute the startup function
runStartupFcn(app, @startupFcn)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
end
The Panel is
Error is like this
Error using hgjavacomponent
Functionality not supported with figures created with the uifigure function. For more information, see Graphics Support in
App Designer.
Error in javacomponentdoc_helper
Error in javacomponentdoc_helper
Error in javacomponent (line 95)
[hcomponent, hcontainer] = javacomponentdoc_helper(varargin{:});
Error in test/startupFcn (line 19)
javacomponent(jScrollPane, [50,200,100,100], fig);
Error in test (line 52)
runStartupFcn(app, @startupFcn)
Error using hgjavacomponent
Functionality not supported with figures created with the uifigure function. For more information, see Graphics Support
in App Designer.
Error in javacomponentdoc_helper
Error in javacomponentdoc_helper
Error in javacomponent (line 95)
[hcomponent, hcontainer] = javacomponentdoc_helper(varargin{:});
Error in test/startupFcn (line 19)
javacomponent(jScrollPane, [50,200,100,100], app.UIFigure);
Error in test (line 52)
runStartupFcn(app, @startupFcn)
Is there a way to apply javacomponent into app designer?

채택된 답변

Yair Altman
Yair Altman 2019년 9월 24일
Java components are not supported by AppDesigner or uifigures. This is not a temporary limitation - it is a fundamental outcome from the radically different technology of uifigures (browser webpages that display HTML and JavaScript components) compared to legacy figures (which where essensially Java windows and so could contain Java components). Because of this, this limitation is not expected to be resolved. EVER. You will need to find a non-Java component to fit your needs in AppDesigner/uifigures. Unfortunately, there is no simple replacement for the CheckBoxList that I am aware of. You might try to find a JavaScript component that implements this and then add it to the uifigure using the new uihtml function (R2019b). Alternatively, you could use javacomponent in a legacy figure, but note that this is expected to stop working in some not-too-distant future Matlab release.
  댓글 수: 2
Hassan
Hassan 2020년 4월 11일
Dear Yair;
I am using your example to make multi-color texts in figures. Now I understand that this example is not implemented in a UIFigure of UILabel. Do you have a workaround to make to add multiple colors to a text output?
Thanks, HM
Yair Altman
Yair Altman 2020년 4월 12일
if you use R2019b or newer, you can use the uihtml function to embed custom HTML code (including multi-color text labels) in uifigures

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

추가 답변 (1개)

Ivan Qin
Ivan Qin 2019년 5월 8일
I have the same question. I put the call to javacomponent in the app Construct section and it did not work either.
Anybody has idea?

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by