From 43b1c4e2cf3e458993313d06bf12f99490043bb7 Mon Sep 17 00:00:00 2001 From: Sebastiano Poggi Date: Thu, 5 Oct 2023 19:48:34 +0200 Subject: [PATCH] Fix items not showing in some cases in Swing ...with the classic Swing solution --- .../ideplugin/swingsample/SwingDemoPanel.kt | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/samples/ide-plugin/src/main/kotlin/org/jetbrains/jewel/samples/ideplugin/swingsample/SwingDemoPanel.kt b/samples/ide-plugin/src/main/kotlin/org/jetbrains/jewel/samples/ideplugin/swingsample/SwingDemoPanel.kt index ebe31dbf74..59b21cc0c1 100644 --- a/samples/ide-plugin/src/main/kotlin/org/jetbrains/jewel/samples/ideplugin/swingsample/SwingDemoPanel.kt +++ b/samples/ide-plugin/src/main/kotlin/org/jetbrains/jewel/samples/ideplugin/swingsample/SwingDemoPanel.kt @@ -24,6 +24,7 @@ import org.jetbrains.jewel.samples.ideplugin.ContentSource import javax.swing.BoxLayout import javax.swing.DefaultListModel import javax.swing.JPanel +import javax.swing.ListSelectionModel import javax.swing.event.DocumentEvent import javax.swing.event.DocumentListener @@ -92,9 +93,17 @@ class SwingDemoPanel(scope: CoroutineScope) : BorderLayoutPanel() { border = JBUI.Borders.empty(4) } + private var lastSelected: ContentItem? = null private val contentList = JBList().apply { + selectionMode = ListSelectionModel.SINGLE_SELECTION + addListSelectionListener { - onListSelectionChanged() + if (selectedValue != lastSelected) { + lastSelected = selectedValue + onListSelectionChanged() + } else { + println("!!! Ignoring already selected") + } } } @@ -162,6 +171,9 @@ class SwingDemoPanel(scope: CoroutineScope) : BorderLayoutPanel() { private fun onListSelectionChanged() { val selection = contentList.selectedValue sidePanel.display(selection) + + revalidate() + repaint() } }