How can I put a javacomponent in the app designer?

14 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

Yair Altman
Yair Altman il 24 Set 2019
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 Commenti
Hassan
Hassan il 11 Apr 2020
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 il 12 Apr 2020
if you use R2019b or newer, you can use the uihtml function to embed custom HTML code (including multi-color text labels) in uifigures

Accedi per commentare.

Più risposte (1)

Ivan Qin
Ivan Qin il 8 Mag 2019
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?

Categorie

Scopri di più su Develop Apps Using App Designer in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by