Is there a way to set the background color of the ...
# compose-desktop
d
Is there a way to set the background color of the native window before content is rendered? There's a white flash before the app's (dark) content appears. All of the answers I saw for this were specific to Android.
I even tried making the window not visible for a second to let the content render, but it still flashed white on making it visible...perhaps content doesn't render while it's invisible.
t
Hey, I was wondering did you find a good solution for this?
d
Nope, it's on my "wait and see" pile for Compose 🙂
t
Yeah I am trying to fix a few things from that pile
The JetBrains Toolbox app does not flash white so it should be possible
d
No, it is transparent (but with the OS frame) until everything is drawn, then it appears.
good point
t
Found the issue, you can set the background color in the Window content using
window.background =
, but at that point the window is already shown, so its too late.
The line I linked is where you need to call
this.window.background = …
which works
ComposeWindow is actually a JFrame, which has a default background color
Calling the following before creating a window also works, but not sure what it all affects:
Copy code
javax.swing.UIManager.getDefaults().apply {
    put("control", javax.swing.plaf.ColorUIResource(java.awt.Color.RED))
}
I am now using the following workaround. Call it just before the Window function.
Copy code
@Composable
private fun fixWhiteFlashOnStartup() {
    val background = MaterialTheme.colors.background
    remember(background) {
        UIManager.getDefaults().apply {
            put("control", ColorUIResource(background.toArgb()))
        }
    }
}
d
interestingly, i'm still getting the flash
I got it after trying
Copy code
javax.swing.UIManager.getDefaults().apply {
    put("control", javax.swing.plaf.ColorUIResource(java.awt.Color.RED))
}
too
t
Did you call that before Window(onCloseRequest..)?
It works for me on macOS
d
Windows here.
t
Hmm maybe this trick does not work on Windows, will have to try that
d
thank you! you're the best