JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
15.73k stars 1.14k forks source link

SwingPanel goes out of parent component on resize #4147

Open Walingar opened 7 months ago

Walingar commented 7 months ago

Describe the bug When SwingPanel contains JPanel with BorderLayout and component in CENTER some content may be out of parent component on resizing

Affected platforms Select one of the platforms below:

Versions

To Reproduce Use this code:

import androidx.compose.foundation.layout.*
import androidx.compose.material.Text
import androidx.compose.ui.Modifier
import androidx.compose.ui.awt.SwingPanel
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.singleWindowApplication
import java.awt.Dimension
import javax.swing.JPanel
import javax.swing.JTree

fun main() = singleWindowApplication {
    Box(modifier = Modifier.width(300.dp).width(200.dp)) {
        Column(modifier = Modifier.fillMaxWidth()) {
            Text("Text", modifier = Modifier)
            SwingPanel(factory = {
                JPanel().apply {
                    add(JTree().apply {
                        preferredSize = Dimension(200, 300)
                    })
                }
            }, modifier = Modifier.fillMaxWidth().height(200.dp))
        }
    }
}

And try to resize the window. Tree content will go away -- it shouldn't

While if we use such code:

import androidx.compose.foundation.layout.*
import androidx.compose.material.Text
import androidx.compose.ui.Modifier
import androidx.compose.ui.awt.SwingPanel
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.singleWindowApplication
import java.awt.Dimension
import javax.swing.JPanel
import javax.swing.JTree

fun main() = singleWindowApplication {
    Box(modifier = Modifier.width(300.dp).width(200.dp)) {
        Column(modifier = Modifier.fillMaxWidth()) {
            Text("Text", modifier = Modifier)
            SwingPanel(factory = {
                JTree().apply {
                    preferredSize = Dimension(200, 300)
                })
            }, modifier = Modifier.fillMaxWidth().height(200.dp))
        }
    }
}

Everything works good

okushnikov commented 1 month ago

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.