
Undocumented Secrets of MATLAB
®
-Java Programming144
% Add the MATLAB plot canvas to the new pure-Java frame
awtinvoke(jf2,'add(Ljava.awt.Component;)',jCanvas);
awtinvoke(jf2,'setVisible',1); % the plot shows in the Java Frame
% Hide original MATLAB figure – only the Java frame remains visible
set(gcf,'Visible','off');
% Update the MATLAB plot, actually modifying the axes in the JFrame
plot(1:23); % plot in Java window is updated using regular HG MATLAB
awtinvoke(jf2,'show()'); % re-render (repaint) the plot
MATLAB axes reparented onto a pure-Java container
Note how we use jf2.show() in the last command above: For some unknown reason, ...