Giter Club home page Giter Club logo

Comments (28)

edvin avatar edvin commented on May 14, 2024 3

FX.primaryStage is not initialized yet in the init method, so you would have to do this in start():

    override fun start(stage: Stage) {
        stage.icons += Image("file:///path/to/icon")
        super.start(stage)
    }

Also remember to supply a valid URL to the Image constructor (starting with proto://). Does that help?

from tornadofx.

edvin avatar edvin commented on May 14, 2024 2

Allright, try the shiny new addStageIcon function :) Needed to add boolean property that keeps track of "app initialized state". This can be run from the init function.

from tornadofx.

edvin avatar edvin commented on May 14, 2024 1

No worries :) I'll start preparing for a release and document the features from the changelog as well :)

from tornadofx.

thomasnield avatar thomasnield commented on May 14, 2024 1

AH! Tricky... that explains everything.

from tornadofx.

edvin avatar edvin commented on May 14, 2024

Sorry for beeing dense, but I'm not sure I understand what you mean, can you elaborate?

from tornadofx.

thomasnield avatar thomasnield commented on May 14, 2024

Unless I missed an already built-in feature with JavaFX, if you want to apply an icon to every window, stage, dialog, etc. you have to do it manually to each one. Is it possible to set the icon in one place and it is used for every View and Fragment-backed dialog?

from tornadofx.

edvin avatar edvin commented on May 14, 2024

Ah! That would be easy for Fragments using the openModal() function, but not for Views. I'll think about this and find a solution, shouldn't be too hard :)

from tornadofx.

edvin avatar edvin commented on May 14, 2024

If we add a function that creates a new stage, this function could automatically copy the icons from the primary stage. So whenever you instantiate a stage via this option, your icons would be in sync. Would that be satisfactory?

from tornadofx.

thomasnield avatar thomasnield commented on May 14, 2024

That would be awesome!

from tornadofx.

edvin avatar edvin commented on May 14, 2024

OK, we'll go for that. I moved Fragment.openModal to UIComponent to it supports View as well, and added the icon trick to that one. I think the name might be a misnomer now, but could you check if this works for you, or tell me what we would need to change? We could rename this, fix it and make a backwards compatible version of openModal and possibly deprecate that to move forward.

from tornadofx.

thomasnield avatar thomasnield commented on May 14, 2024

I'll follow up on this when I get a chance today...

from tornadofx.

thomasnield avatar thomasnield commented on May 14, 2024

Haven't forgotten this. I will follow up when I resume writing the guide tomorrow. I'm kind of testing as I document stuff : )

from tornadofx.

edvin avatar edvin commented on May 14, 2024

@thomasnield did you get around to testing if this works as intended for you? :)

from tornadofx.

thomasnield avatar thomasnield commented on May 14, 2024

I just got to my computer to hammer through my queue of things : ) Give me ~30 minutes

from tornadofx.

edvin avatar edvin commented on May 14, 2024

Perfect :) Working on closing a few issues, looking at Alert builders now :)

from tornadofx.

thomasnield avatar thomasnield commented on May 14, 2024

Working on it now...

from tornadofx.

thomasnield avatar thomasnield commented on May 14, 2024

Sorry if I'm being slow today, what exactly would I configure to set up a universal icon with this modification?

from tornadofx.

edvin avatar edvin commented on May 14, 2024

Haha, no problem :) Either configure the stage.icons in your App start() function, or any other place later on via FX.primaryStage.icons.

The stage should get the icons, and any new stage created with the openModal() function should get this icon. I can create a demo app if needed :)

from tornadofx.

thomasnield avatar thomasnield commented on May 14, 2024

Yeah I just figured that out with the FX.primaryStage.icons. Trying to run it now.

from tornadofx.

thomasnield avatar thomasnield commented on May 14, 2024

Random problem. Keep getting this error when trying to run this application.

Exception in Application constructor
Exception in thread "main" java.lang.NoSuchMethodException: MyAppTest.main([Ljava.lang.String;)
    at java.lang.Class.getMethod(Class.java:1786)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:125)
class MyAppTest: SingleViewApp() {
    override val root = VBox()

    init {
        FX.primaryStage.icons += Image("C:\\git\\tornadofx\\src\\test\\kotlin\\logo.png")

        with(root) {
            button("Press Me") {
                setOnAction { MyDialog().openModal() }
            }
        }
    }

    class MyDialog: Fragment() {
        override val root = VBox()

        init {
            with(root) {
                label("Dialog")
            }
        }
    }
}

from tornadofx.

thomasnield avatar thomasnield commented on May 14, 2024

Yep! Got it. Very nice. I approve.

class MyAppTest: SingleViewApp() {
    override val root = VBox()

    init {
        with(root) {
            button("Press Me") {
                setOnAction { MyDialog().openModal() }
            }
        }
    }

    override fun start(stage: Stage) {
        super.start(stage)
        FX.primaryStage.icons += Image("logo.png")
    }

    class MyDialog: Fragment() {
        override val root = VBox()

        init {
            with(root) {
                label("Dialog")
            }
        }
    }
}

from tornadofx.

edvin avatar edvin commented on May 14, 2024

Cool! You can apply the icon to stage, no need to apply it to primaryStage.

I could however add a function that will add this as a "global" icon, and even make sure that the primaryStage is available when it's added. Let me try, hang on.

from tornadofx.

thomasnield avatar thomasnield commented on May 14, 2024

That might be more intuitive : )

from tornadofx.

edvin avatar edvin commented on May 14, 2024

Can you attach logo.png so I have something to test with? hehe :)

from tornadofx.

edvin avatar edvin commented on May 14, 2024

Hmm. That was a bit more involved than I though. Hang on.

from tornadofx.

thomasnield avatar thomasnield commented on May 14, 2024

Sorry here is the logo. For some reason addStageIcon isn't applying the icon...

logo

from tornadofx.

edvin avatar edvin commented on May 14, 2024

Thanks :) Hmm.. yeah, I can't set a breakpoint in that method. I'll report back when I have it sorted!

from tornadofx.

edvin avatar edvin commented on May 14, 2024

Oh, wow :) That's the first time Kotlin has bitten me...

I declared the function as fun addStageIcon(icon: Image) = { code here } instead of fun addStageIcon(icon: Image) { code here }. In other words, the function created a function instead of executing the code. Commited a fix now :)

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.