I tried to migrate from 0.3.2 to 0.4.0 and it seem...
# compose-desktop
t
I tried to migrate from 0.3.2 to 0.4.0 and it seems that the SwingPanel doesn't have the same behavior anymore. In the 0.4.0, the JPanel doesn't follow the modifier rules anymore. When the JFrame is big, the JPanel is too small, when the JFrame is small, the JPanel is too big and it overlaps Compose components. Is this a bug ?
On 0.3.2, the JPanel follow the layout rules :
message has been deleted
But in 0.4.0, it looks like that (with the same code) :
message has been deleted
(The orange things is the Jpanel, the rest is Composable components)
i
This snippet shows that JPanel still fits into the parent
Box
🤔:
Copy code
import androidx.compose.desktop.SwingPanel
import androidx.compose.desktop.Window
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.requiredSize
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import java.awt.Color
import javax.swing.JPanel

fun main() = Window {
    Box(Modifier.requiredSize(400.dp, 100.dp)) {
        SwingPanel(
            factory = {
                JPanel().apply {
                    background = Color.RED
                }
            },
            modifier = Modifier.fillMaxSize()
        )
    }
}
Can you check if you replace
SwingPanel
by just
Box
- will
Box
have the right size?
t
I replaced a SwingPanel by a Box. The Box worked as intented and followed the Modifier rules.
I think that the behavior of SwingPanel changed for modifier like "weight" or "fillMaxSize" but it works with "requiredSize". I don't understand because it worked well on 0.3.2
i
If it works with the usual
Box
and doesn't work with
SwingPanel
then probably it is a bug. I reproduced a simlar issue. If we fix it, then your issue also will be fixed (probably).
t
Thank you for the answer! I will wait for the fix
i
As a temporary fix you can probably wrap your SwingPanel into Box and move Modifier from SwingPanel to this Box
t
Thank you very much for your help. It worked