From 455b634fdd4d0f02a86b3b28b87f2dc33ee2bb25 Mon Sep 17 00:00:00 2001 From: Roman Sedaikin Date: Tue, 16 Feb 2021 09:35:16 +0300 Subject: [PATCH] Updated Swing interoperability tutorial according to build153. --- tutorials/Swing_Integration/README.md | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/tutorials/Swing_Integration/README.md b/tutorials/Swing_Integration/README.md index fccd5be701..efd32125c8 100644 --- a/tutorials/Swing_Integration/README.md +++ b/tutorials/Swing_Integration/README.md @@ -37,6 +37,7 @@ import java.awt.event.ActionEvent import java.awt.event.ActionListener import javax.swing.JFrame import javax.swing.JButton +import javax.swing.SwingUtilities import javax.swing.WindowConstants val northClicks = mutableStateOf(0) @@ -53,7 +54,7 @@ fun main() { SwingComposeWindow() } -fun SwingComposeWindow() { +fun SwingComposeWindow() = SwingUtilities.invokeLater { val window = JFrame() // creating ComposePanel @@ -205,7 +206,14 @@ fun main() { SwingPanel( background = Color.White, modifier = Modifier.size(270.dp, 90.dp), - componentBlock = { swingBox(dec) } + factory = { + JPanel().apply { + setLayout(BoxLayout(this, BoxLayout.Y_AXIS)) + add(actionButton("1. Swing Button: decrement", dec)) + add(actionButton("2. Swing Button: decrement", dec)) + add(actionButton("3. Swing Button: decrement", dec)) + } + } ) Spacer(modifier = Modifier.height(20.dp)) @@ -225,17 +233,6 @@ fun Button(text: String = "", action: (() -> Unit)? = null) { } } -fun swingBox(action: (() -> Unit)? = null): Component { - val box = JPanel() - box.setLayout(BoxLayout(box, BoxLayout.Y_AXIS)) - - box.add(actionButton("1. Swing Button: decrement", action)) - box.add(actionButton("2. Swing Button: decrement", action)) - box.add(actionButton("3. Swing Button: decrement", action)) - - return box -} - fun actionButton( text: String, action: (() -> Unit)? = null