How to use SceneBuilder's DarkTheme in my application - java

Firstly, is it legal to use the dark theme of JavaFX's SceneBuilder 2 in my application? Since it is open source now here: SceneBuilder/css
Secondly, how to do this if legal? Or just for training purposes if not legal?
I tried to download the ThemeDark.css file from the link above and add it to my fxml file, but i see no change applied.
Any ideas ?
Edit (what I did):
I have downloaded the .css file and pasted it in package css.
Then I added these lines in my .fxml file (with the <> symbols but I removed them in this question as they hid the text if present) :
stylesheets
URL value="#/css/ThemeDark.css"
/stylesheets
See below resulting screenshot: (themeDark not applied)

If you are using SceneBuilder you can add a global css sheet to it and be happy with the new look.
Alternative, if you want to set it within your code you can use
scene.getStylesheets().clear();
scene.getStylesheets().add("path/stylesheet.css"); // Modify to your path
to add a style-sheet. Notice that you should put your style-sheet in a resource folder in your application, just to keep everything cleaned up.

Related

How to solve java file mapped to not java file type text

I wanted to add a java class to a project, but I did a mistake and added it as a text file. Then, I removed it and tried to add it again as a java class, but unfortunately it doesn't work anymore. And I get the following error:
Unable to parse template "Class" Error message: ABC.java mapped to not java file type text
As I searched, I faced some solutions like
this one but I can't find File Type under Editor or anything similar that I can change as suggested in the solution.
Any help would be appreciated.
PS: I am using IntelliJ 2018.3.4.
Thanks in advance,
Go on File->Settings and a dialog will open. In that dialog navigate on the left part to Editor/File Types and then you need to choose from the section Recognized File Types Java Class and remove from bottom section the problematic extension (note you have a small minus button on the right)
https://www.jetbrains.com/help/idea/creating-and-registering-file-types.html
This is a variant of Markov's answer that worked in my scenario.
Try going to File->Settings->Editor->File Types and to the Recognized File Types tab. Click the "Auto-detect file type by content" choice, and delete the name of the file you are trying to create from the "File Name Patterns" section by using the minus button.
Select required file type in top list (Recognized File Types) -- do it for "Text files"
In bottom list (Registered Patterns) select undesired pattern -- "SomeFileName.java"
Click on "-" (Minus) button to remove pattern from the list
Repeat 1-2-3 for other undesired patterns
If desired, you can also do this manually by editing config file while IDE is closed. Because it's IDE-wide setting, it is not stored in .idea folder (which has project settinsg only) -- the file to look for is called filetypes.xml and shoudl be located in ~/Library/Preferences/IntelliJIdeaXX/options ( see http://devnet.jetbrains.net/docs/DOC-181 for other OS etc )
Certainly inelegant, but you can simply copy the contents of the file to the clipboard (ctrl-c or similar), delete the file (maybe make a temporary backup somewhere outside the project), then in IntelliJ go to the desired package, right click, select new, select Java Class, name it correctly, and then you can paste in the contents of your file (ctrl-v or similar).

How to disable error highlighting in VS Code?

I need to disable error highlighting in Java files in VS Code. VS Code tries to check a Groovy file while thinking it is a Java file.
As you can see in the picture all imports after the first and the types after the first field are highlighted red (due to missing semicolons). However I do not want the error check for this Groovy file.
NOTE: I only have the plugins Clang, RedHat.Java, Markdown PDF, Sort Lines, and Uncrustify installed. Even if I disable all the red highlighting is visible.
open your preferences file and add this
"java.validate.enable": false
I didn't try it for java, but it works for typescript.
I found this:
"problems.decorations.enabled": false,
You should disable the linter, which is by default enable in VS Code.
To do so you can go to File-> Prefrences -> setting
I wouldn't think this is necessary but you might try:
"files.associations": {
".groovy": "groovy"
}
in your user settings, assuming your file extension is .groovy. If it is something else, just set it to "groovy" as well. When I create a .groovy file with your content or gibberish I get no error linting at all. What is your file extension and what does Vscode call it in the bottom right of the editor? You can click on that file type to change its file associations. See modifying Vscode file extensions.

Use modena.css with JavaFX2 and Java 7

I am developing a JavaFX application. Unfortunately, I am restricted to Java 7, thus also restricted to JavaFX2. However, I would like to include the default theme from JavaFX 8 Modena. Hence, I downloaded the modena.css and put it into my src/main/resources/ folder. Now I would like to set this css as my default theming.
Seeing How to set JavaFX default skin I tried setting
System.setProperty( "javafx.userAgentStylesheetUrl","src/main/resources/modena.css")
but the styling wasn't any different.
How can I set another default css file other than caspian using Java 7 and JavaFx 2?
src part of the path looks wrong. You need to provide the path which is valid at runtime, check your build or target folder to see what is it.
Most probably right path is main/resources/modena.css
You can also write next in your code to see if path is correct:
System.out.println(getClass().getResource("main/resources/modena.css"));
if it's null — your path is wrong.

JavaFX + SpringBoot, cant load css

i need a help understanding what is happening in my project, anyways i have javafx with springboot:
i have folder structure like this :
So i want to access from my java/controller folder, and i need my css file that is under resources folder, in css folder.
I tried every possible way, to load my css and nothing seems to work except :
Directly loading css through fxml (which i wish to evade)
using this code also works, but only in IDE, if i create JAR it does not work anymore :
File f = new File("src/main/resources/css/main.css");
paneRoot.getStylesheets().add("file:///" + f.getAbsolutePath().replace("\\", "/"));
When i do check of f.exists() i get true, so path is ok, but when i use this :
paneRoot.getStylesheets().add(getClass().getResource("src/main/resources/css/main.css").toExternalForm());
or
paneRoot.getStylesheets().add("src/main/resources/css/main.css");
it does not work,in first code line, where i use .toExternalForm(), program crashes reporting nullPointer.
Now i honestly do not know what is issues here, i tried with 2 different IDE-s, i tried clearing cashe, rebulding and cleaning application, but every time same issue.
If i need to provide further code, i will i just need to understand this.

JavaFX usage of "in jar" images in css

I am trying to add background image to some pane in my javafx application, the image is located inside the package resources.img and the css is located inside the package resources.css
if i setting the background image programmatically like suggested in this thread:
Setting background image by javafx code (not css)
it works fine but i would like to know if i can set the background image from the css file itself.
i tried
-fx-background-image: url("#../img/myImage.png");
but then the css interpreter didn't find the image file.
is it possible to do what i want via css?
JavaFX CSS parser has a limitation like
#-keyword statements are ignored.
described in "Limitations" section of CSS Reference Guide. It may be the cause of your problem though didn't confirm myself. Can you try like this: -fx-background-image: url("../img/myImage.png");
or -fx-background-image: url("resources/img/myImage.png");.
Perhaps someone it will be useful.
If you specified: -fx-background-image: url("resources/img/myImage.png");.
It's possible that standalone .jar file will successfully load the image while IDE(like Eclipse) won't. It because IDE alters path and will search something like: C:/My_project/resources/css/resources/img/myImage.png.
It means root for specified path will folder with css file instead of .jar package

Categories

Resources