edvin / tornadofx

Lightweight JavaFX Framework for Kotlin
Apache License 2.0
3.67k stars 269 forks source link

After build nothing is displayed on screen. #1316

Open f4004 opened 3 years ago

f4004 commented 3 years ago

I fixed all of problems about gradle and building. But I still have a problem. Having clicked Run I get BUILD SUCCESSFUL but nothing appear. And program is ended by doing nothing. Why?

Build output:

BUILD SUCCESSFUL in 920ms
1 actionable task: 1 executed
Task execution finished.
SKeeneCode commented 3 years ago

Build what? Are you building the tornadofx library or your own project?

f4004 commented 3 years ago

I'm build my own project. I'm trying to use TornadoFX library in my project. I've tried this code.

SKeeneCode commented 3 years ago

Put a launch function outside:

Main.kt

class HelloWorld : View() {
    override val root = hbox {
        label("Hello world")
    }
}

class HelloWorldApp : App(HelloWorld::class, Styles::class)

class Styles : Stylesheet() {
    init {
        label {
            fontSize = 20.px
            fontWeight = FontWeight.BOLD
            backgroundColor += c("#cecece")
        }
    }
}

fun main() {
    launch<HelloWorldApp>()
}

and then in your gradle.build.kts:

application {
    mainClass.set("MainKt")
}

Then run using gradle. Does this work?

f4004 commented 3 years ago

Thanks for your answer. But it doesn't work anyway. Still same.

SKeeneCode commented 3 years ago

Are you sure you're running the run task? Gradle > Tasks > Application > run?

image

f4004 commented 3 years ago

I got new error this time when I tried your code:

src\main\kotlin\main.kt: (1, 20): Unresolved reference: View

When I tried the code I've wrote, I got this error:

src\main\kotlin\main.kt: (4, 27): Unresolved reference: HelloWorld

From Gradle > Run section.

SKeeneCode commented 3 years ago

Have you got tornadofx imported using import tornadofx.*?

f4004 commented 3 years ago

Yeah now it is working. Thank you. It needs to import javafx.scene.text.FontWeight. Thank you again. Can I some question regarding this codes.

SKeeneCode commented 3 years ago

No problem. Feel free to ask anything else - if I can answer I will :)

f4004 commented 3 years ago
SKeeneCode commented 3 years ago
  • What is the difference between Run from Intellij and Run from Gradle and why nothing is displayed when I clicked Run(from Intellij)?

Are you sure you're actually running the application in intellij? By clicking the green arrow and not just the build button? image I'm guessing there is something mistaken with your set up.

I think I might need to look at your project to determine exactly what is going wrong.

You can read more about exactly what a gradle run task does here.

  • Why we usedmainClass ("MainKt") instead of mainClassName = "MainKt" in build.gradle.kts? Actually when I've tried both are works fine.

mainClassName = "MainKt" is deprecated, the other way seems to be the appropriate way of doing it now.

f4004 commented 3 years ago

Are you sure you're actually running the application in intellij? By clicking the green arrow and not just the build button? image

As your seen following image, I was clicking green arrow nothing appears after build. Actually when I click Run from top menu appears two section there. kotlinandtornadofx (with Gradle icon) and MainKt (with Kotlin icon) file. When I clicked MainKt, it gives a lot of debug error, but kotlinandtornadofx file doesn't give error but doesn't run anything neither. image After first Run in Gradle, kotlinandtornadofx - run section has been added.

SKeeneCode commented 3 years ago

When I clicked MainKt, it gives a lot of debug error

Can you post the errors?

f4004 commented 3 years ago

I'm sorry to keep you waiting. I was deleted that configuration before but I've created a new project and I tried. MainKt works fine. But why my previous project had Gradle symbol? Seem like MainKt and kotlinandtornadofx is run by another compiler or something.

image

SchweinchenFuntik commented 3 years ago

well, without the configuration window, it is difficult to understand which task you are launching, if you yourself did not specify the name, then perhaps you have a custom task

f4004 commented 3 years ago

well, without the configuration window, it is difficult to understand which task you are launching

In fact, I wonder, there is only one task to run: it is project. Perhaps I don't know tasks.

SchweinchenFuntik commented 3 years ago

terminal (linux): ./gradlew run (wrapper) or gradle run