Make it possible to define Icons in FXML

Issue #2 resolved
Manuel Mauky created an issue

At the moment there is no easy way to define fontawesomefx icons directly in FXML (correct me if I'm wrong).

As a workaround I've create a little helper like this:

public class Icon extends Label {
    public Icon(@NamedArg("value") AwesomeIcon value){
        AwesomeDude.setIcon(this, value);
    }
}

In my FXML file I can use it this way:

<Button text="Test">
    <graphic>
        <Icon>
            <value>
                <AwesomeIcon fx:value="EDIT"/>
            </value>
        </Icon>
    </graphic>
</Button>

This works just fine but maybe there are better solutions. Anyway, maybe something like this could be added to the library.

Comments (3)

  1. Jens Deters repo owner

    Indeed good idea! Was already on my list. I like your approach. If you don't mind I would consider to add it to the API.

  2. Manuel Mauky reporter

    Of cause you can add this to the API if you like it.

    I have tweaked my solution a little bit:

    public class Icon extends Label {
    
        public Icon(AwesomeIcon icon){
            AwesomeDude.setIcon(this, icon);
        }
    
        public Icon(@NamedArg("awesomeIcon") String awesomeIcon){
            this(AwesomeIcon.valueOf(awesomeIcon));
        }
    }
    

    With this modification you can write smaller FXML code:

    <Button text="Test">
        <graphic>
            <Icon awesomeIcon="EDIT" />
        </graphic>
    </Button>
    

    The first constructor can still be used from Java code to have full type safety.

  3. Log in to comment