Desktop - Transparent AppWindow #646
Replies: 10 comments 19 replies
-
You can try accessing the underlying AWT window through LocalAppWindow.current.window and setting the background to a transparent color. This will only work if the underlying window system supports pero-pixel transparency. |
Beta Was this translation helpful? Give feedback.
-
Probably the specific platform you're running on does not support translucency for Swing windows then. There's some code at https://docs.oracle.com/javase/tutorial/uiswing/misc/trans_shaped_windows.html#capability that you can run in a pure Swing sample to verify that. |
Beta Was this translation helpful? Give feedback.
-
Are you using a
shows a partially translucent grey window with a red text |
Beta Was this translation helpful? Give feedback.
-
Or in your example:
where you need to call |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
I don't know if that helps, but under Windows I get the below result when window is displayed. For a short time it shows up the actual transparency. fun main() = Window(undecorated = true) {
key(true) {
LocalAppWindow.current.window.background = java.awt.Color(0, 0, 0, 128)
}
MaterialTheme {
Column(modifier = Modifier.background(Color.Transparent)) {
// App()
}
}
} Adding transparent background to |
Beta Was this translation helpful? Give feedback.
-
I think it is caused by skia default background, but I am not sure |
Beta Was this translation helpful? Give feedback.
-
In case other people are still looking for a solution to this, I found the following worked for me.
I hope that helps! |
Beta Was this translation helpful? Give feedback.
-
you can write like this. fun main() {
SwingUtilities.invokeLater {
val size = Dimension(500, 300)
val transparentFrame = JFrame()
transparentFrame.size = size
transparentFrame.isUndecorated = true // this line hide default windowbar
transparentFrame.isVisible = true
transparentFrame.setLocation(
(Toolkit.getDefaultToolkit().screenSize.width - transparentFrame.size.width) / 2,
(Toolkit.getDefaultToolkit().screenSize.height - transparentFrame.size.height) / 2
)
val composePanel = ComposePanel()
composePanel.size = size
composePanel.setContent {
transparentFrame.iconImage = painterResource("icons/compose.svg").toAwtImage(
density = Density(1f, 1f),
layoutDirection = LayoutDirection.Rtl
)
Row(
modifier = Modifier.background(Color.Red)
) {
Text("测试")
}
}
transparentFrame.contentPane.add(composePanel)
transparentFrame.pack() // it important
}
} In this way, you can get a completely transparent window containing only one composite panel component |
Beta Was this translation helpful? Give feedback.
-
Is hard for me to apply this code. i know about other coding lenguages but its being so hard to apply transparent window in a java project with eclipse |
Beta Was this translation helpful? Give feedback.
-
How?
I need a fully transparent window. I want to make an overlay for the game.
I know how to do this with Swing or JavaFX. But no matter how I try, compose makes a white background
Beta Was this translation helpful? Give feedback.
All reactions