Could someone give me some tips on how to style my JavaFx Application. I am using scene builder to put my app together. Would I have to import css files into my javafx project. An explanation on this would be greatly appreciated :)
You have two ways to do this, (from the SceneBuilder/inside the FXML) or the Java Code :
//Java Code :
root.getStylesheets().add(getClass().getResource("style.css").toExternalForm());
For the scenebuilder you use a relative path to the location of your file.css and assign to each graphical element (node) its (Id/StyleClass) in the properties section of the SceneBuilder.
The Id is marked by # sign example :
#styleID{
-fx-background-color:red;
}
Related
I am putting styles in CSS file and import it correctly in fxml file, but styles are not showing in scene builder. But when I run the app all the styles are applied correctly. I am using intelijIdea Can someone please help me
I know this is old, but I believe certain names aren't picked up on, it seems.
For example, when I use the name, "content" for a class, or "title", those classes will not show up in the list of available class styles to apply to components. This seems like a silly, arbitrary thing to not even remotely document, but as far as I can tell, that was my issue.
I've been at this problem trying to find workarounds for weeks now and I am starting to give up. I must be doing something fundamentally wrong. Anyway, this is my situation. I have previously made a neat little program using JavaFX but have now discovered Scene Builder and want to build it all again using this tool. The project includes several components that are frequently reused such as the one below. This is made up of a label, a slider, a text field and another custom component, an InfoIcon.
I have understood that the done thing is to import the custom component (the InfoIcon) as a .jar file into Scene Builder when building my SliderVariable as I call it. This works great and I can run a small demo of my SliderVariable from within Eclipse by creating a main method, a scene and making a SliderVariable in this scene. As mentioned this works great. Importing or Including the InfoIcon does not do what I want (I don't think) because then I cannot easily make changes to the InfoIcon (or its controller) and update my SliderVariable and then see the effects in the final product.
The problems arise when I want to take it one step further and in turn use my SliderVariable in Scene Builder. I do as with the InfoIcon. I export my slider variable to a non-executable jar and then import it into Scene Builder. Here Scene Builder complains that it cannot find any UI components and thus fails to import it. I have discovered that this is because when I export the SliderVariable as a jar it does not also package its dependencies meaning the InfoIcon doesn't get bundled with it and that the compiler cannot find this component as I try to use it.
I have tried to solve this with FatJar which I cannot get working (and it seems like it is not in use any more). I have tried Maven where I couldn't import the Maven project dependency of the InfoIcon in the FXML of the SliderVariable. Finally I have also tried simply not importing a jar but instead including the source code of InfoIcon in a separate package of SliderVariable but then I couldn't import it into my FXML. I am desperate. What do people normally do if they want to reuse custom components with their own controllers in Scene Builder? Is this even done? Should I just give up :'(?
This unwieldly post must be highly confusing but I do not know how to make it clearer. Any sort of response would be greatly appreciated and if you do not believe this forum is the right place to post something like this (which it probably isn't) please point me to someplace else where I am more welcome.
Many thanks.
EDIT 1: I have now added a folder in my project called Dependencies. In here I put a copy (not a reference to) my InfoIcon.jar.
I then add this .jar file to my Build Path and remove the old one. I then enter SceneBuilder and reimport the InfoIcon jar but this time from the Dependencies folder I just created. At this point the small project test I've made still runs fine. I then export as JAR file with the following settings and hit finish.
I then try to import it into Scene Builder and Scene Builder tells me it cannot find any UI components.
EDIT 2: Should I select these items?
Note that the jar file is in Dependencies but also in Referenced Libraries (which is not visible here). This type of selection makes it so that Scene Builder can find and Import the InfoIcon but not the SliderVariable.
When you export InfoIcon, you can simply select the packages and classes related to it in the Eclipse's package explorer (or other similar explorer views), and choose export.
Similarly, when you try to export SliderVariable control, you need to choose everything you have selected in InfoIcon, on top of other files that are needed by SliderVariable control itself.
If InfoIcon is imported into SliderVariable project as a JAR file, then you would need to manually select that JAR file during the export of SliderVariable.
I have a java fxml file with some controls in it. I want to change the style of them by using my custom css file. So I use Scene Builder and loaded the css file. It worked. But when I make changes on the css the controls on the scene builder do not respond to them. Furthermore reverting (deleting or commenting out) the changes on the css file and reloading it on the fxml through scenebuilder results in making changes to the style, the ones I had commented out or deleted. Does it use any cache, should I close and reload scene builder?
I have done some javaFX(1.x 2.x 8.x) applications without scene builder before. Today I started to use it (GLUON JavaFX Scene Builder 8.0.0) just to get what is it, because have some more javaFX tasks.
I found similar problem. I spend two hours just to attach css file to simple GridPane, and cannot do this :(. I opened my recent project fxml, and builder cannot open it, while I remove project specific import from it... (It shows error and exceptions stack trace, so I spend some time to found out why it occurs). After I fix that, my old project FXML opened scene and applied style from css (there were just colors, no images or other resources was used).
Every time I changed css - scene builder shows that it found changes, but not render them... cool, right? Even though I preview from menu.
Total: Every time you change css you should reopen fxml.
javafx set application ico
when i create java project , add jfxrt.jar
it's right
new Image(getClass().getResourceAsStream("../images/customLogo.png"))
but this in javafx project
it's wrong.
how can i get relative path do this in javafx project.
I think that you should take a look on the Image API and this another link where how to put the icon is answered.
If you were generating a jar, you can use
new Image("/path/to/image")
The path to the image starting with "/", will be an absolute path inside the jar. I strongly recommends go to the Image API to check all the options, is really well documented.
Hope it helps
So what is the exception? Where did you create the project (which IDE). As a general rule never use ..-paths when doing look ups although the might work on the filesystem they e.g. break inside jar-files IIRC.
I am using the vaadin plugin for grails, and am trying to define some custom styles. Where within my grails appliction should I put the .css? My Vaadin application is in /vaadin/ I have tried creating a /vaadin/themes/mytheme/ folder and then putting my styles.css file in there, but still had no luck. Any help would be greatly appreciated. New to grails and new to vaadin, and am pulling my hair out over small stuff like this and can't get any of the actual legwork done until I can figure these things out..
Any way of doing inline styling would be fine with me too, at this point. I really just need some way to write explicit style..
Thanks
You need to put it into /web-app/VAADIN/themes/mytheme
You can have a look at the completed addressbook tutorial (with added Gorm and Spring Security Core support)
With the latest version of the plugin:
The name of the file must be styles.css (or styles.scss, which will then be compiled to styles.css by the command grails prod war)
The file must be located in /web-app/VAADIN/themes/mytheme , where the last part is the name of your style
In your UI file, use the #Theme annotation, for example
#Theme("mytheme")
#VaadinUI(path = '/')
class MyUI extends UI {
// ...
In VaadinConfig.groovy, specify the styles used by the application:
themes = ['mytheme']