how to have JLabel update it's text value in another thread using Kotlin. (in Configurable::createComponent)

I have a Configurable class in which my createComponent() method looks somewhat like this:

override fun createComponent(): JComponent = com.intellij.ui.layout.panel {
row("DB info") {
cell {
browserLink("H2", "https://www.h2database.com")

val versionLabel = JLabel()

kotlin.run {
val driver = org.h2.Driver.load()
versionLabel.text = driver.majorVersion
versionLabel.updateUI() // <--- I've tried with and without this line
}
}
}
}

When I run the project I can see the link but the version number never appears. The process is running though as I can put a breakpoint on it and can see that the H2 db driver is loaded and returns a version number.

1 comment
Comment actions Permalink

I've actually got this working now with the following:

 

override fun createComponent(): JComponent = com.intellij.ui.layout.panel {
row("DB info") {
cell {
browserLink("H2", "https://www.h2database.com")

kotlin.run {
val d = org.h2.Driver.load()
JLabel("${d.majorVersion}.${d.minorVersion}")() // <--- Should I use JLabel or JBLabel here?
}
}
}
}

So the only question that I have now is whether or not I should be using JLabel or JBLabel for my UI and should I have wrapped that up in ApplicationManager.getApplication().invokeLater {}?

0

Please sign in to leave a comment.