MATLAB: How to suppress warnings about javacomponent being deprecated

deprecatedguijavajavacomponentMATLABundocumented

I've got a GUI that uses Java functionality and requires use of the javacomponent function. While javacomponent is still available, though, I'd like to suppress the warnings about it being removed in a future release. There's no warning shown in the editor, with mlint, or with checkcode, so I can't suppress the warning like usual.
Is there a way to suppress this particular warning?

Best Answer

Wrap your javacomponent code as follows:
oldWarningState = warning('off', 'MATLAB:ui:javacomponent:FunctionToBeRemoved');
[hjcomponent, hcontainer] = javacomponent(...);
warning(oldWarningState); % revert to displaying the warning
If you have multiple calls to javacomponent in your GUI code, you may wish to revert the warning state only at the end of your GUI creation code (take care to do it even in case of exceptions or early function bail-outs, so that you don't get stuck forever with the warning turned off.
If you want to permanently turn off this warning, run warning('off','MATLAB:ui:javacomponent:FunctionToBeRemoved') in your Matlab Command Window and then you won't need to modify the code at all.
General note: to know which warning identifier cause each warning that is displayed, run the following:
warning('on','verbose')
This will include the display of the warning ID ('MATLAB:ui:javacomponent:FunctionToBeRemoved' in this specific case) next to the warning message. For example:
Warning: JAVACOMPONENT will be removed in a future release. For more information see UI Alternatives for MATLAB Apps on mathworks.com.
(Type "warning off MATLAB:ui:javacomponent:FunctionToBeRemoved" to suppress this warning.)