Search code examples
javajavafxescapingfxml

How do i use '%' symbol in FXML statements


When I write fxml markup, I get a warning from my IDE when i use the '%' symbol within strings, such as:

<Label text="% Tax:" />

I also receive a RuntimeException when running my JavaFX application and building the UI.

So my question is: How do i use the '%' symbol correctly?


Solution

  • Despite the comments, I just tested this in an old project, and you do seem to be somewhat correct. However, it is not a compile error! For instance, if I write something like this in fxml:

    <Label text="% Output:" />
    

    I get an InvocationTargetException when building the UI. All you need to do is to escape the symbol like this:

    <Label text="\% Output:" />
    

    The reason you think this is a compile error is likely because your IDE is marking it as incorrect. This is just your IDE being clever.

    And by the way, your question could have been a lot clearer.