Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question
1  
Specifying a background colour for CreateDialog seems to help on my system at least, e.g. CreateDialog[..., Background -> LightGray]. –  Heike Apr 17 '12 at 18:08
    
@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. –  István Zachar Apr 17 '12 at 18:30
    
@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... –  tkott Apr 17 '12 at 19:42
    
Does this issue affect v.7? I cannot figure out how you made this happen. –  Mr.Wizard Apr 17 '12 at 21:24
    
Does Background->Opacity[0] work? –  celtschk Apr 17 '12 at 22:08
show 3 more comments

2 Answers

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}}}
share|improve this answer
    
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. –  István Zachar Apr 17 '12 at 23:48
    
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? –  David Carraher Apr 17 '12 at 23:56
    
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. –  István Zachar Apr 18 '12 at 0:07
add comment

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

share|improve this answer
    
While this is a good workaround, unfortunately I need the default background (i.e. the OS's original). –  István Zachar Apr 17 '12 at 23:22
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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