Comments (28)
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.
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.
No worries :) I'll start preparing for a release and document the features from the changelog as well :)
from tornadofx.
AH! Tricky... that explains everything.
from tornadofx.
Sorry for beeing dense, but I'm not sure I understand what you mean, can you elaborate?
from tornadofx.
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.
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.
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.
That would be awesome!
from tornadofx.
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.
I'll follow up on this when I get a chance today...
from tornadofx.
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.
@thomasnield did you get around to testing if this works as intended for you? :)
from tornadofx.
I just got to my computer to hammer through my queue of things : ) Give me ~30 minutes
from tornadofx.
Perfect :) Working on closing a few issues, looking at Alert builders now :)
from tornadofx.
Working on it now...
from tornadofx.
Sorry if I'm being slow today, what exactly would I configure to set up a universal icon with this modification?
from tornadofx.
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.
Yeah I just figured that out with the FX.primaryStage.icons
. Trying to run it now.
from tornadofx.
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.
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.
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.
That might be more intuitive : )
from tornadofx.
Can you attach logo.png so I have something to test with? hehe :)
from tornadofx.
Hmm. That was a bit more involved than I though. Hang on.
from tornadofx.
Sorry here is the logo. For some reason addStageIcon
isn't applying the icon...
from tornadofx.
Thanks :) Hmm.. yeah, I can't set a breakpoint in that method. I'll report back when I have it sorted!
from tornadofx.
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)
- TornadoFx ClassCastException HOT 1
- Accessing nodes with less code HOT 4
- Advanced Data Controls Guide Clarification HOT 1
- Unbind TextField text property from non-String property HOT 2
- Font not loading HOT 1
- AsyncKt cannot access class com.sun.glass.ui.Application HOT 5
- EventBus.fire does not check for listeners of superclass types HOT 1
- Set window icons for Alerts
- Hot reload doesn't work with openjdk
- a bug with toggleClass HOT 2
- TornadoFx stackpane overlapping with menubar
- How can i build a native image using tornadofx HOT 1
- Localization of german Double values
- Data Driven TreeView HOT 1
- how to use field()? | and why field() cant' be used without form()? HOT 2
- Tornadofx with Spring security
- Is this not longer maintained? HOT 8
- Looking for maintainers HOT 1
- Guilde is not available HOT 1
- Documentation does not work HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tornadofx.