Code Monkey home page Code Monkey logo

Comments (21)

edvin avatar edvin commented on May 18, 2024

I'm assuming you get this example to work in IDEA when you remove the main method, right? Your problem is that you want to override the startup sequence somehow?

EDIT: If you created a Kotlin run configuration in IDEA, it will not recognize JavaFX applications. If you choose the normal Application type, everything works fine.

First of all, your main method is not static, it's just a method sitting in a class, so Java doesn't recognize it as an application entry point.

Normally you declare Kotlin main methods as a package level construct, ie. outside your App class:

fun main(args: Array<String>) {
    Application.launch(MainApp::class.java, *args)
}

You would then tell IDEA that your main class is called MainAppKt.

But why do you need to provide the main method? Doesn't IntelliJ recognise MainApp as runnable? Without a main method you should simply specify MainApp and it should work.

from tornadofx.

edvin avatar edvin commented on May 18, 2024

@thomasnield see my edit above - maybe you chose the Kotlin run configuration instead of the one called Application?

from tornadofx.

edvin avatar edvin commented on May 18, 2024

I created a page in the Wiki where I mention this IDEA specific caveat :)

https://github.com/edvin/tornadofx/wiki/Application-Startup

from tornadofx.

thomasnield avatar thomasnield commented on May 18, 2024

Perfect! Yeah I was just trying to get it to run. Creating the IDEA Application configuration did the trick. Thanks a lot and I look forward to playing with this library.

from tornadofx.

edvin avatar edvin commented on May 18, 2024

Nice :) Let me know if you need any further help :)

from tornadofx.

thomasnield avatar thomasnield commented on May 18, 2024

Thank you sir, will do!

from tornadofx.

hastebrot avatar hastebrot commented on May 18, 2024

Yeah, main() needs to be on file level (i.e. within FooKt for the file foo.kt). Luckily Kotlin allows multiple mains within a package, so it allows multiple Applications.

By the way: IDEA treats JavaFX Applications in Java to allow to omit the main method. I opened a feature request, to have the same for Kotlin: https://youtrack.jetbrains.com/issue/KT-8773

from tornadofx.

edvin avatar edvin commented on May 18, 2024

Thanks, @hastebrot - that's what I noticed also. I voted for KT-8773 as well :) Good to get the ball rolling on that.

from tornadofx.

thomasnield avatar thomasnield commented on May 18, 2024

@hastebrot I just started to figure that out regarding the file level as well as the omission of the main() method. Thanks for filing that as it would be convenient.

from tornadofx.

thomasnield avatar thomasnield commented on May 18, 2024

I voted as well.

from tornadofx.

thomasnield avatar thomasnield commented on May 18, 2024

I hate to tangent, but did I build this 3-tabbed pane optimally? Even if some builders could be added, really like the succinct nature of this already.

class MainApp : App() {
    override val primaryView = MainView::class

    class MainView : View() {

        override val root = with(HBox()) {
            this += with(TabPane()) {
                with (tabs) {
                    add(Tab("Tab 1"))
                    add(Tab("Tab 2"))
                    add(Tab("Tab 3"))
                }
                this
            }
            this += with (VBox()) {
                this += Button("Bttn 1")
                this += Button("Bttn 2")
                this
            }
            this
        }
    }
}

from tornadofx.

hastebrot avatar hastebrot commented on May 18, 2024

At least the second element of the HBox could be created like this:

class Main : View() {
    override val root = StackPane()

    init {
        with(root) {
            setPrefSize(500.0, 500.0)
            hbox {
               vbox {
                   button("Bttn 1")
                   button("Bttn 2")
               }
            }
        }
    }
}

from tornadofx.

hastebrot avatar hastebrot commented on May 18, 2024

I wonder why IntelliJ doesn't suggest me tabpane() and tab() from tornadofx/Builders.kt.

from tornadofx.

hastebrot avatar hastebrot commented on May 18, 2024

Or do you want to create the form without Builders?

from tornadofx.

thomasnield avatar thomasnield commented on May 18, 2024

I was wondering that too. Is there a function for tabpane?

from tornadofx.

hastebrot avatar hastebrot commented on May 18, 2024

Yes, it is right at the top of tornadofx/Builders.kt.

Update: That could be new functions that were added after release 1.2.2.
Update update: Yes, they were added right after the last release.

from tornadofx.

thomasnield avatar thomasnield commented on May 18, 2024

I must have overlooked that. I assumed the builder was missing but that does not appear to be the case. Odd. That aside I'm really liking this library. This comes a long way from my messy Swing applications from back in the day.

I'm going to use RxJavaFX with this next to get some reactive stuff going. Please let me know if we need to file a bug with JetBrain on the tabpane issue.

class MainApp : App() {
    override val primaryView = MainView::class

    class MainView : View() {

        override val root = StackPane()

        init {
            with(root) {
                setPrefSize(500.0, 500.0)
                hbox {
                    this += with(TabPane()) {
                        with (tabs) {
                            add(Tab("Tab 1"))
                            add(Tab("Tab 2"))
                            add(Tab("Tab 3"))
                        }
                        this
                    }
                    vbox {
                        button("Bttn 1")
                        button("Bttn 2")
                    }
                }
            }
        }
    }
}

from tornadofx.

hastebrot avatar hastebrot commented on May 18, 2024

a bug with JetBrain on the tabpane issue

It's all ok. IntelliJ didn't find it, because it doesn't exist in TornadoFX 1.2.2.

from tornadofx.

thomasnield avatar thomasnield commented on May 18, 2024

I was just about to post that because my decompiled BuildersKt.class didn't have it.

// IntelliJ API Decompiler stub source generated from a class file
// Implementation of methods is not available

package tornadofx

private fun <T : javafx.scene.Node> opcr(pane: javafx.scene.layout.Pane, node: T, op: (T.() -> kotlin.Unit)? /* = compiled code */): T { /* compiled code */ }

public fun javafx.scene.layout.Pane.button(text: kotlin.String /* = compiled code */, op: (javafx.scene.control.Button.() -> kotlin.Unit)? /* = compiled code */): javafx.scene.control.Button { /* compiled code */ }

public fun javafx.scene.layout.Pane.checkbox(text: kotlin.String? /* = compiled code */, op: (javafx.scene.control.CheckBox.() -> kotlin.Unit)? /* = compiled code */): javafx.scene.control.CheckBox { /* compiled code */ }

public fun javafx.scene.layout.Pane.datepicker(op: (javafx.scene.control.DatePicker.() -> kotlin.Unit)? /* = compiled code */): javafx.scene.control.DatePicker { /* compiled code */ }

public fun javafx.scene.layout.Pane.gridpane(op: (javafx.scene.layout.GridPane.() -> kotlin.Unit)? /* = compiled code */): javafx.scene.layout.GridPane { /* compiled code */ }

public fun javafx.scene.layout.Pane.hbox(spacing: kotlin.Double? /* = compiled code */, children: kotlin.collections.Iterable<javafx.scene.Node>? /* = compiled code */, op: (javafx.scene.layout.HBox.() -> kotlin.Unit)? /* = compiled code */): javafx.scene.layout.HBox { /* compiled code */ }

public fun javafx.scene.layout.Pane.imageview(url: kotlin.String? /* = compiled code */, op: (javafx.scene.image.ImageView.() -> kotlin.Unit)? /* = compiled code */): javafx.scene.image.ImageView { /* compiled code */ }

public fun javafx.scene.layout.Pane.label(text: kotlin.String /* = compiled code */, op: (javafx.scene.control.Label.() -> kotlin.Unit)? /* = compiled code */): javafx.scene.control.Label { /* compiled code */ }

public fun javafx.scene.layout.Pane.progressBar(initialValue: kotlin.Double? /* = compiled code */, op: (javafx.scene.control.ProgressBar.() -> kotlin.Unit)? /* = compiled code */): javafx.scene.control.ProgressBar { /* compiled code */ }

public fun javafx.scene.layout.Pane.progressIndicator(op: (javafx.scene.control.ProgressIndicator.() -> kotlin.Unit)? /* = compiled code */): javafx.scene.control.ProgressIndicator { /* compiled code */ }

public fun javafx.scene.layout.HBox.spacer(prio: javafx.scene.layout.Priority /* = compiled code */, op: (javafx.scene.layout.Pane.() -> kotlin.Unit)? /* = compiled code */): javafx.scene.layout.Pane { /* compiled code */ }

public fun javafx.scene.layout.VBox.spacer(prio: javafx.scene.layout.Priority /* = compiled code */, op: (javafx.scene.layout.Pane.() -> kotlin.Unit)? /* = compiled code */): javafx.scene.layout.Pane { /* compiled code */ }

public fun javafx.scene.layout.Pane.stackpane(initialChildren: kotlin.collections.Iterable<javafx.scene.Node>? /* = compiled code */, op: (javafx.scene.layout.StackPane.() -> kotlin.Unit)? /* = compiled code */): javafx.scene.layout.StackPane { /* compiled code */ }

public fun javafx.scene.layout.Pane.textarea(value: kotlin.String? /* = compiled code */, op: (javafx.scene.control.TextArea.() -> kotlin.Unit)? /* = compiled code */): javafx.scene.control.TextArea { /* compiled code */ }

public fun javafx.scene.layout.Pane.textfield(value: kotlin.String? /* = compiled code */, op: (javafx.scene.control.TextField.() -> kotlin.Unit)? /* = compiled code */): javafx.scene.control.TextField { /* compiled code */ }

public fun javafx.scene.layout.Pane.titledPane(title: kotlin.String, node: javafx.scene.Node): javafx.scene.control.TitledPane { /* compiled code */ }

public fun javafx.scene.layout.Pane.toolbar(vararg nodes: javafx.scene.Node, op: (javafx.scene.control.ToolBar.() -> kotlin.Unit)? /* = compiled code */): javafx.scene.control.ToolBar { /* compiled code */ }

public fun javafx.scene.layout.Pane.vbox(spacing: kotlin.Double? /* = compiled code */, children: kotlin.collections.Iterable<javafx.scene.Node>? /* = compiled code */, op: (javafx.scene.layout.VBox.() -> kotlin.Unit)? /* = compiled code */): javafx.scene.layout.VBox { /* compiled code */ }

from tornadofx.

edvin avatar edvin commented on May 18, 2024

I just released TornadoFX 1.2.3 with the new builders (and binding support), so now you can write:

override val root = HBox()

init {
    with(root) {
        tabpane {
            tab("Tab 1") {
                // Content for tab 1 here
            }
            tab("Tab 2") // and so forth :)
        }
    }
}

If you find any missing builders or have more questions about how to do stuff, don't hesitate to ask @thomasnield. (But create new issues :)

Thanks for helping out again @hastebrot :)

from tornadofx.

thomasnield avatar thomasnield commented on May 18, 2024

Awesome thanks! I may file PR's if I find any missing builders, so you guys can focus on the more complicated stuff you're working on.

from tornadofx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.