How can I put a javacomponent in the app designer?
14 次查看(过去 30 天)
显示 更早的评论
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/188080/image.png)
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?
0 个评论
采纳的回答
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
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
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
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?
0 个评论
另请参阅
类别
在 Help Center 和 File 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!