Skip to content

Commit

Permalink
Fix items not showing in some cases in Swing
Browse files Browse the repository at this point in the history
...with the classic Swing solution
  • Loading branch information
rock3r committed Oct 5, 2023
1 parent 496d6ed commit 43b1c4e
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -92,9 +93,17 @@ class SwingDemoPanel(scope: CoroutineScope) : BorderLayoutPanel() {
border = JBUI.Borders.empty(4)
}

private var lastSelected: ContentItem? = null
private val contentList = JBList<ContentItem>().apply {
selectionMode = ListSelectionModel.SINGLE_SELECTION

addListSelectionListener {
onListSelectionChanged()
if (selectedValue != lastSelected) {
lastSelected = selectedValue
onListSelectionChanged()
} else {
println("!!! Ignoring already selected")
}
}
}

Expand Down Expand Up @@ -162,6 +171,9 @@ class SwingDemoPanel(scope: CoroutineScope) : BorderLayoutPanel() {
private fun onListSelectionChanged() {
val selection = contentList.selectedValue
sidePanel.display(selection)

revalidate()
repaint()
}
}

Expand Down

0 comments on commit 43b1c4e

Please sign in to comment.