Subscribe Bookmark RSS Feed

Setting an Icon for a Modal Window


Super User


Jul 28, 2015

It's not as easy as you'd think.  For some reason you can't send the "<< Set Window Icon()" command during the creation process.  Normally this is fine, since you can just send the command to the window right after.  Like so:

nw = New window("test", <<Modal, text box("test"));

nw << Set Window Icon("$SAMPLE_IMAGES/pi.gif");

However, when it comes to modal windows we run into some interesting issues.  First, the modal window prevents any further scripts from running until the user interacts with the modal window.  This typically means by the time we can send the Set Window Icon command, the window has already closed.  To get around this, we can schedule the send command, for 0 seconds into the future.  What this does, is it tells JMP to send the command as soon as possible, AKA when you stop running other commands.  Since the modal window will stop the script from continuing, it will be right after the window is displayed.  Which is perfect for our intent.

From the above you might think OK great, I'll just schedule it, put the code above the window creation and we are good?

schedule(0, nw << Set Window Icon("$SAMPLE_IMAGES/pi.gif"));

nw = New window("test", <<Modal, text box("test"));


See the problem with this is that the nw object isn't created until after the Modal Window is responded to.  Unlike other windows, the nw object won't contain a reference to the display window, instead it is set up to store the data object sent to it by the modal window.  For the most part this will be {Button = -1} or {Button = 1} depending on whether you hit  "Ok" or "Cancel".  Thus, to solve this problem we need a display object we can send the command to.  The textbox would work, but I chose to wrap it in a list box and send it there. 

Thus we get (after a little refactoring):

iconFunction = Function({box, path},

       box << Set Window Icon(path);


s = schedule(0, iconFunction(vlb, "$SAMPLE_IMAGES/pi.gif"));

report(s) << Show Window( 0 );

nw = New window("test", <<Modal, vlb = vlistbox(text box("test")));

This was just an interesting quirk of JSL I ran into today.  What are some of your favorite quirks of JSL?