https://kotlinlang.org logo
Title
t

Tristan B.

06/01/2021, 8:00 AM
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 :
But in 0.4.0, it looks like that (with the same code) :
(The orange things is the Jpanel, the rest is Composable components)
i

Igor Demin

06/01/2021, 8:39 AM
This snippet shows that JPanel still fits into the parent
Box
🤔:
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

Tristan B.

06/01/2021, 11:18 AM
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

Igor Demin

06/01/2021, 1:27 PM
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

Tristan B.

06/01/2021, 2:32 PM
Thank you for the answer! I will wait for the fix
i

Igor Demin

06/01/2021, 3:14 PM
As a temporary fix you can probably wrap your SwingPanel into Box and move Modifier from SwingPanel to this Box
t

Tristan B.

06/01/2021, 3:24 PM
Thank you very much for your help. It worked