Issue
I just started a desktop project with Intellij, built with the default generated code, ran it on Linux, and it worked. Then I added a counter variable for the button text (shown as follows), it also ran as before. But when I click on the button, the change of text on reaction to the click takes as long as 10 seconds. Wonder what can be wrong.
I am running Xubuntu 22.04.
@Composable
@Preview
fun App() {
var text by remember { mutableStateOf("Hello, World!") }
var ic by remember { mutableStateOf(0) }
MaterialTheme {
Button(onClick = {
ic++
text = "Hello, Desktop! $ic"
}) {
Text(text)
}
}
}
fun main() = application {
Window(onCloseRequest = ::exitApplication) {
App()
}
}
My build.gradle:
import org.jetbrains.compose.compose
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.6.10"
id("org.jetbrains.compose") version "1.1.1"
}
group = "me.xxxx"
version = "1.0"
repositories {
google()
mavenCentral()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
}
dependencies {
implementation(compose.desktop.currentOs)
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "11"
}
compose.desktop {
application {
mainClass = "MainKt"
nativeDistributions {
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
packageName = "Test"
packageVersion = "1.0.0"
}
}
}
Solution
Well, it turns out a VirtualBox setting issue. I run Xubuntu on VirtualBox hosted by MacBook Pro. I need to set graphics controller to VMSVGA on VirtualBox. So now it's responsive.
Answered By - LeoXJ Answer Checked By - Pedro (WPSolving Volunteer)