Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SwingPanel not clipped by containing widget #1449

Closed
jimgoog opened this issue Nov 23, 2021 · 5 comments
Closed

SwingPanel not clipped by containing widget #1449

jimgoog opened this issue Nov 23, 2021 · 5 comments
Assignees
Labels
desktop enhancement New feature or request swing interop Swing interop issue

Comments

@jimgoog
Copy link
Collaborator

jimgoog commented Nov 23, 2021

Consider the following code:

fun main() = application {
    Window(onCloseRequest = ::exitApplication) {
        Column {
            Card(modifier = Modifier.size(100.dp), shape = RoundedCornerShape(30.dp), elevation = 10.dp) {
                Box(Modifier.fillMaxSize().background(Color.Green)) {
                    SwingPanel(background = Color.Green, factory = { JLabel(" ")}, update={it.text = " "})
                }
            }
        }
    }
}

It should look like this:
Screen Shot 2021-11-23 at 1 13 21 PM

But it actually looks like this:
Screen Shot 2021-11-23 at 1 12 55 PM

Notice the content of the box is not clipped by the rounded corners of its container card. You can reproduce by commenting out the SwingPanel and notice that the content is clipped by the containing card when there is no SwingPane inside the card.

cc @igordmn

@igordmn
Copy link
Collaborator

igordmn commented Nov 24, 2021

Unfortunately this is how SwingPanel works currently. I added docs about it.

We draw all Swing components over all Compose components.

To properly fix the issue, we need to draw Swing into texture/bitmap (preferably with hardware acceleration), or map all Swing Graphics2D operations to Skia operations.

@igordmn igordmn added desktop enhancement New feature or request swing interop Swing interop issue labels Nov 24, 2021
@felixdivo
Copy link
Contributor

Possibly related to #1202

@jimgoog
Copy link
Collaborator Author

jimgoog commented Nov 29, 2021

Huh, skijagraphics2d is actually kinda cute/clever - it could also improve the situation for screenshot testing too, which currently crashes if a widget contains a swing subcomponent.

I don't think I have the knowledge to recommend one approach or the other, but as @felixdivo observed, many things are going to be broken if clipping and layering are wrong.

@MatkovIvan MatkovIvan assigned MatkovIvan and unassigned Rsedaikin Jun 7, 2024
@MatkovIvan
Copy link
Member

Fixed by JetBrains/compose-multiplatform-core#915 (under the flag)

@okushnikov
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
desktop enhancement New feature or request swing interop Swing interop issue
Projects
None yet
Development

No branches or pull requests

6 participants