JavaFX CSS image not rendering - css

I am working on a Gradle JavaFX project in IntelliJ. My question is essentially "How do I get a background-image URL working for JavaFX in CSS?" for which the answer would be:
.button{
-fx-background-image: url("/image/CloseButtonBlack.png");
}
except that this doesn't work for me. After much experimentation, I have discovered that if I move the file up one level so it lies directly in the resources folder, everything works. Because of this, I believe that the reason the file doesn't display when it lies within the image folder is that the image folder is not marked as a resource folder. If I were not using Gradle, I believe I could fix this just by using IntelliJ's Project Structure -> Modules menu. Since I am using Gradle though, I am thinking that the correct way to fix this would be to write some code in build.gradle so that Gradle knows the image folder is a resource folder. If I am right, what code is it that I need to write to get my background image to display while it lies in the image folder?

Related

How to check CSS loaded size in Angular Application

Hope you all doing great.
I am using SCSS and Bootstrap in my Angular Application and as we know once Angular app runs, it converts these SCSS files to CSS version of it.
How can I check CSS file size generated as a whole for application as I need to show some reports for optimization tasks.
Any idea. I tried googling and here on Stack Overflow but couldn't find required solution. I can't even see any CSS file in Network tabs of Browsers.
Any Suggestion?
Assuming you are using Angular CLI for your project, which uses webpack internally...
Once you build a project. A dist directory is generated in the project root. Take a look into it and you'll find all the .js and .css bundles it might have generated.
Note - The size will vary based on what kind of build you do. For a production build, the sizes are going to be minimal, for other kinds of builds, if any, the sizes may differ.
You should go first in the Networks tab then reload the page. Once you reload it, click on CSS filter then you would see all the list of CSS included in your app, with the file size.
I didnt find any css generated in Network like above answer but I did a trick.
I went to webpack folder and there I found one generated CSS. ( Searched through a random CSS Selecto ).
I right clicked and saved it on desktop. If you check the properties of this CSS file, it shows the size in KB.

How to add the path of images in a QML project correctly

I'm going to practice this example and for that I created a Qt Quick Console 2 Application project named Main2 using Qt Creator 4.3.0 on a windows 7 machine.
The code for main.qml looks like this:
and I get the following errors in the Application Output window:
The program has unexpectedly finished.
C:\Users\Abbasi\Documents\QML\Main2\Main2\build-Main2-Desktop_Qt_5_9_0_MinGW_32bit-Debug\debug\Main2.exe crashed.
Starting C:\Users\Abbasi\Documents\QML\Main2\Main2\build-Main2-Desktop_Qt_5_9_0_MinGW_32bit-Debug\debug\Main2.exe...
QML debugging is enabled. Only use this in a safe environment.
What is the problem with the paths or anything please?
The images are in a folder named images on the Desktop. How to move them to a folder under the project, a step-by-step means please?
copy the images folder to your project folder
right click on your project - add new - Qt - resource file - images.qrc
right click on that - add existing files, goto /images and select what you want to add
alternatively, you can directly use the "add existing directory" option to add all files in a directory
Then from QML you simply:
Image { source: "images/whatever.jpg" }
This way the images are neatly packed inside your executable. Which is OK in most cases, unless you have gigabytes of images. It also helps prevent people replacing your stock images with profane versions ;)
Creating a separate resource file for images will do wonders for your build times.
If you are that keen on file system access, be that absolute (please don't do that ever in production) or relative, you will have to prepend a file:// to the path to tell Qt you want the file system rather than internal resources.
Update: As revealed by your main.cpp file, the actual problem is you are using a project template that uses QQmlApplicationEngine. The tutorial you are following dates back to the days before that, and uses QQuickView. The latter can have any QML element as a root, but the former needs to have an ApplicationWindow, which is the reason you are not getting any output. So you need to wrap your existing code in an ApplicationWindow:
ApplicationWindow {
visible: true
width: 640
height: 480
// your code goes here
}
use qrc: with image URL might work
Image { source: "qrc:images/whatever.jpg" }

Best place for CSS and LESS external libs in PhpStorm or PyCharm project

I want my IDE to see Bootstrap files for CSS classes autocompletion and on-the-fly LESS compiling. But I don't want to store Bootstrap inside my project folder structure and copy libraries in each project. How can I make IDE know where is libs?
Some approaches I tried.
Using relative paths. #import '../../../../../Bootstrap 3/less/mixins'; does not look good. Moreover, despite import statement is correct (without red underlining), IDE does not "know" about imported mixins. When I just copy libraries, IDE "knows" about them.
Connect as JS libs. I see them in project files view. LESS syntax checker cannot locate them, no matter what path i specify. Import statement is underlined with red wavy line.
Now, I can use only copy and paste technique or use links (or directory junctions). I am not sure that this is correct way.
I tried this PhpStrom and PyCharm, but I suppose that WebStorm cannot resolve this problem too.
You can add a folder where your Bootstrap files are stored as additional content root to each of your projects (Settings/Directories, Add content root). See also WEB-7452

CSS: background-image: url with absolute path to another disk partition

I want to write some stylesheet and use some backgrounds in larger project, but I don't know path where the graphics will be in future in the project. So I want to only prepare it, and paths will be replaced then.
I don't want to move graphics or stylesheets. Project is on C: using xampp and graphics on D: Question is how can I import the graphics?
I tried something like
background: url("file://localhost/D:/brig/task/image.png");
background: url("file://D:/brig/task/image.png");
background: url("D://brig/task/image.png");
Can I use absolute path like this??
Firstly I suggest you to use a WYSIWYG editor like dreamweaver, visual studio or any for instance.
Then make a project folder with the name brig and put all the relevant directories, images, etc inside it relevantly. Then when you open your HTML or css in the editor, select your main project and then when you put the images inside your HTML or CSS via src or url respectively, it will automatically make it relative and fetch it from that place where you have originally stored in your project.
For instance,
background: url("../task/image.png");
This ../ means a relative path for one level up directories. So in future, when you put your graphic files on the same path, this will fetch the images via a relative path as mentioned.
Hope this helps.
Your css is able to get pictures as long the path is still working just by navigating with ../../../etc. It should work with other partitions on the server as good as normal url paths from web. If the partition is not on your server, just make a folder at your webroot. It's not advisable to outsorce too much of your website.
Users can't access your file system, so css doesn't work with it. If you want to use the graphics from you d: you need to move them to the c: in the folder of your site. It can be in a subfolder.

How can i set application icon in javafx2

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.

Resources