# Avoiding jiggle in palettes

I have a palette containing a Grid with dynamics. As it runs it jiggles horizontally. Here's a minimal example:

CreatePalette[
Dynamic[Grid[{{"Some text of unknown length",
DateString["SecondShort"]}}, BaseStyle -> 15],
UpdateInterval -> 1], Saveable -> False]


I don't want to just set WindowSize because I don't know the size before it's run, and unfortunately Grid doesn't have like an ImageMargins or ImagePadding or anything like that. I'm sure there must be some simple way of doing this.

• If you don't know the size before it's run, than I think you're out of luck. No matter what size the initial window is, at some point it is possible for the contents to be bigger than the window. – Carl Woll Nov 20 '19 at 23:08
• Would placing your variable width content in Panes of fixed widths help? e.g. Pane[DateString["SecondShort"], 20, FrameMargins -> 0, ImageMargins -> 0, ContentPadding -> False] – Chip Hurst Nov 21 '19 at 0:36
• Or perhaps a fixed width font. e.g. Style[DateString["SecondShort"], FontFamily -> "Courier"] – Chip Hurst Nov 21 '19 at 0:38
• @ChipHurst that almost works, but the palette changes size when it wraps around from 59 back to 0... I tried getting the padding form right, but I can't avoid the jiggle :( – M.R. Nov 21 '19 at 1:04
• Which one? I don't see the jiggle with Pane. For the Style idea, padding the string prevents the 59 -> 0 jiggle. Style[StringPadRight[DateString["SecondShort"], 2, " "], FontFamily -> "Courier"] – Chip Hurst Nov 21 '19 at 1:21

Let's assume that the content's size is unknown up front but stays more or less the same later. You can adjust the size after it appears by using current value of WindowSize or to do this up front by using Rasterize[whatever, "RasterSize"].

Let's try with the former one as Rasterize needs to be adjusted to use palettes' styles anyway.

CreatePalette[
DynamicModule[{},
Pane[
Dynamic[
Grid[{{"Some text of unknown length", DateString["SecondShort"]}},
BaseStyle -> 15], UpdateInterval -> 1],
Full,
FrameMargins -> 5,
Alignment -> {Left, Center}
],
SynchronousInitialization -> False,
Initialization :> (
CurrentValue[EvaluationNotebook[], WindowSize] =
1.05 AbsoluteCurrentValue[EvaluationNotebook[], WindowSize]
)
]
, Saveable -> False

]


• Almost, this stops the window of the palette from jiggling. But two things: if I set SynchronousInitialization->False, then for some reason some of my FE`oneOfMyDyamicModuleSymbols do not format for a few seconds, which looks bad, and still the numbers in the Grid columns continue to jiggle... – M.R. Jan 15 at 19:21