2
$\begingroup$

Why dialogs created with CreateDialog cannot correctly show content with transparent background? The following example generates a plot, with white background, though it should be gray, as that is the default color of the dialog window of Windows. If, however, I move a window in front of the dialog covering it halfway or totally, the background reverts to the default panel-gray (see figures below).

CreateDialog[DocumentNotebook[
   Plot[Sin@x, {x, 0, 2 \[Pi]}, Frame -> True, Axes -> False, 
    Background -> None, ImagePadding -> 30, ImageSize -> 300]
   ]];

Mathematica graphics

(Left: the new dialog as it appears. Middle: covering the dialog halfway with another window, then removing the covering window. Right: Covering the window fully, and then revealing.)

The following approach does not work either:

Background -> Directive[Red, Opacity[0]]

This behaviour is more emphasized if the content is dynamic:

CreateDialog[DocumentNotebook[Column@{
     Slider@Dynamic@n,
     Dynamic@Plot[Sin@x, {x, 0, n \[Pi]}, Frame -> True, Axes -> False, 
       Background -> None, ImagePadding -> 30, ImageSize -> 300]
     }]];

While it appears first with white background, even mouse movements cause it to turn into the desired gray color.

My problem is that I have a gui, where a plot is created and updated in real time. I would like to have its background to be the color of the underlying panel, but it continuously switches between white and gray during updating. Any idea how to overcome this?

$\endgroup$
9
  • 1
    $\begingroup$ Specifying a background colour for CreateDialog seems to help on my system at least, e.g. CreateDialog[..., Background -> LightGray]. $\endgroup$
    – Heike
    Commented Apr 17, 2012 at 18:08
  • $\begingroup$ @Heike Yes, you're right, but I would prefer the default color if possible (as it is OS-dependent). Basically anything helps, that is explicit, e.g. Plot[..., Background -> Yellow] is displayed correctly. Only Plot[..., Background -> None] has this problem. $\endgroup$ Commented Apr 17, 2012 at 18:30
  • $\begingroup$ @IstvánZachar I actually had the same issue you describe with the dynamic dialog window based on a notebook. I just gave up and gave a Background->White command... $\endgroup$
    – tkott
    Commented Apr 17, 2012 at 19:42
  • $\begingroup$ Does this issue affect v.7? I cannot figure out how you made this happen. $\endgroup$
    – Mr.Wizard
    Commented Apr 17, 2012 at 21:24
  • $\begingroup$ Does Background->Opacity[0] work? $\endgroup$
    – celtschk
    Commented Apr 17, 2012 at 22:08

2 Answers 2

1
$\begingroup$

A workaround might be if your looking for one colour for the whole window including the plot is to call the background colour at another place?

CreateDialog[
 DocumentNotebook[
  Column@{Slider@Dynamic@n, 
    Dynamic@Plot[Sin@x, {x, 0, n \[Pi]}, Frame -> True, Axes -> False,
       ImagePadding -> 30, ImageSize -> 300]}, 
  Background -> LightGray]]

this gives:

enter image description here

$\endgroup$
1
  • $\begingroup$ While this is a good workaround, unfortunately I need the default background (i.e. the OS's original). $\endgroup$ Commented Apr 17, 2012 at 23:22
0
$\begingroup$

How about using CreateWindow? It defaults to the same background color (white, in the case of MacOS X) for the slider and the Plot.

CreateWindow[
  DocumentNotebook[
    Column@{Slider@Dynamic@n, 
    Dynamic@Plot[Sin@x, {x, 0, n \[Pi]}, Frame -> True, 
    Axes -> False, Background -> None, ImagePadding -> 30, 
    ImageSize -> 300]}], Background -> None, 
    WindowMargins -> {{654, 654}, {380, 380}},
    WindowTitle -> "Test with CreateWindow"];

CreateWindow


I grabbed the WindowMargins from your code (g, below). You might want to play with some of the other options obtained by AbsoluteOptions:

g= CreateDialog[DocumentNotebook[
   Plot[Sin@x, {x, 0, 2 \[Pi]}, Frame -> True, Axes -> False, 
   Background -> None, ImagePadding -> 30, ImageSize -> 300] ]];

AbsoluteOptions[g, {BackFaceGlowColor, BackFaceColor, 
     BackFaceGlowColor, BackFaceOpacity, BackFaceSpecularColor, 
     BackFaceSpecularExponent, BackFaceTexture, GraphicsColor, 
     GraphicsFocusColor, GraphicsHighlightColor, LineColor, WindowMargins}]

(* out *)
{BackFaceColor -> GrayLevel[1], BackFaceGlowColor -> GrayLevel[0], 
 BackFaceGlowColor -> GrayLevel[0], BackFaceOpacity -> 1, 
 BackFaceSpecularColor -> GrayLevel[0], 
 BackFaceSpecularExponent -> 1.5, BackFaceTexture -> None, 
 GraphicsColor -> GrayLevel[0], 
 GraphicsFocusColor -> GrayLevel[0.499992], 
 GraphicsHighlightColor -> RGBColor[1., 0.560769, 0.26273], 
 LineColor -> GrayLevel[0],
 WindowMargins -> {{654, 654}, {380, 380}}}
$\endgroup$
3
  • $\begingroup$ Sadly, it gives a white background for the plot, while the background of the created notebook visible around the plot itself is the default gray. The options listed are not for the notebook, but mostly for 3D graphics objects, I guess. $\endgroup$ Commented Apr 17, 2012 at 23:48
  • $\begingroup$ The background of the created notebook (in the CreateWindow code) looks white to me, both in the picture and on my computer. Did you by mistake use the CreateDialog code (which is your original code) or the CreateWindow code? $\endgroup$
    – DavidC
    Commented Apr 17, 2012 at 23:56
  • $\begingroup$ Sorry, I wasn't clear enough. The CreateWindow code indeed gives white background, but it does not produce dialog-looking windows. Now if I use CreateDialog/CreateWindow with DialogeNotebook/DocumentNotebook, the background is always white first. In your case, it stays white, while in the other 3 cases it will eventually turn to gray if mouse/other window hovers over. $\endgroup$ Commented Apr 18, 2012 at 0:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.