Forum Stats

  • 3,836,793 Users
  • 2,262,193 Discussions
  • 7,900,114 Comments

Discussions

Absolute URLs for image in CSS files using IntelliJ IDEA

twasyl
twasyl Member Posts: 44
edited Dec 7, 2012 1:41PM in JavaFX 2.0 and Later
Hi everyone,

I'm facing a problem with absolute URLs for images in a CSS file using JavaFX 2.2.3. Given the following FXML:
<?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import java.net.*?>

<AnchorPane xmlns:fx="http://javafx.com/fxml" fx:id="root">
    <stylesheets>
        <URL value="@/com/twasyl/testerfx/resources/style/TesterFX.css" />
    </stylesheets>

    <children>
        <Button prefHeight="128" prefWidth="128">
            <styleClass>
                <String fx:value="testButton" />
            </styleClass>
        </Button>
    </children>
</AnchorPane>
And the given CSS file:
.testButton {
    -fx-background-image: url('/com/twasyl/testerfx/resources/images/globe.png');
    -fx-background-repeat: no-repeat;
}
The display is absolutely correct using NetBeans 7.2.1 but in IntelliJ 12 the image is not displayed. But if in my CSS file I use relative URL like this:
.testButton {
    -fx-background-image: url('../images/globe.png');
    -fx-background-repeat: no-repeat;
}
it's working in both NetBeans and IntelliJ. I've also tried to the URL locator by adding a @ at the beginning of the URL, without success. So I was wondering if it's more an IDE issue, or JavaFX one. Have anyone encounter this problem?

Thank you.
Tagged:

Answers

  • jsmith
    jsmith Member Posts: 2,856
    Make sure your idea project is copying CSS resource files.

    Check:

    Project Settings > Compiler > resource patterns

    http://www.jetbrains.com/idea/webhelp/resource-files.html
  • twasyl
    twasyl Member Posts: 44
    Hi,

    Thank you for your response. It seems the CSS file is included. In the out directory it is present. Moreover, I added the pattern:
    ?*.css
    in the resources pattern but it is still not working. Also, if I modify my CSS file to:
    .testButton {
        -fx-background-image: url('/com/twasyl/testerfx/resources/images/globe.png');
        -fx-background-color: red;
    }
    The red background is displayed but not the image. The only good news is that I made an Ant task to build my test project, and the image is displayed. So I really don't get this behavior in IntelliJ IDEA.
This discussion has been closed.