matlabflexboxmatlab-figurematlab-guiundocumented-behavior

How to add a "tutorial message div" to figures?


After installing R2018b, the first figure I opened contained an interesting message (shown in blue):

Static image

The reason it's interesting is because it contains features like text wrapping, transparency, the fact that the image maintains a constant width even though the text resizes (this reminded me of CSS3 flexbox, hence the tag), etc.

Animation

The last part of the animation is in slow motion, to better show how the div's size follows that of the figure.

In case it matters, I'm using Win 10 v1803.

Question:

I'd like to know how we can draw similar, custom, divs (for a lack of a better word) in our figures. (It's important to stress that this is not a UIFigure!)


What I found so far:


Solution

  • After some digging in the Java side of things (starting from findjobj, followed by a lot of .getComponent(0).getComponent(0)...), I've finally managed to locate the component in question. Here's what I learned:

    1. This component is called InfoPanel, and is part of MATLAB's Java API. The class definition itself is found in:

      MATLAB/R2018b/java/jar/hg.jar!/com/mathworks/hg/util/InfoPanel.class
      
    2. To make it appear, we need to call the static method addBannerPanel, passing in a figure handle:

      com.mathworks.hg.util.InfoPanel.addBannerPanel( figure(randi(1E4)) );
      

      Or another signature that also accepts a custom panel:

      jIP = com.mathworks.hg.util.InfoPanel;
      jIP.setBackground(java.awt.Color(0.8, 0.7, 0.1));
      com.mathworks.hg.util.InfoPanel.addBannerPanel( figure(randi(1E4)), jIP );
      
    3. The MATLAB setting that controls whether this should appear is showinteractioninfobar inside the <prefdir>/matlab.settings XML.

    4. It appears that the "interesting parts" of InfoPanel are private, which means it allows barely any customization (mostly some colors; not the string or the icon), but it should be fairly easy to make a copy of this class and expose all elements we need.