Install JavaFX TableView placeholder in FXML

I know the next problem is a luxury issue:

I would like to keep the initialization of my FXML controller as clean as possible, and so I would like to set the placeholder of my TableView in the FXML file (as I believe this is the best place to store it, because it is just a property and in my case also a constant). I already tried to set it in the FXML file like this:

<TableView placeholder="Some text">

      

This obviously doesn't work because the placeholder property expects Node. That's why I set this placeholder this way in the FXML controller initialization:

Label placeholder = new Label();
placeholder.setText("Some text");
tableview.setPlaceholder(placeholder);

      

It works, but as I said, I would like to manage it from the FXML file only. Some of my questions:

How do I install a placeholder from an FXML file?

Note. Please let me know if possible, because when not, I will fill out a feature request (low priority of course!).

+3


source to share


2 answers


Quite simple, just the usual FXML syntax:

<BorderPane xmlns:fx="http://javafx.com/fxml/1">
<center>
    <TableView>
        <placeholder>
            <Label text="some text"/>
        </placeholder>
    </TableView>
</center>

      



Note. Not everything is a primitive value (can be expressed inline) and therefore needs its own element.

+10


source


I already found the answer using this question: Styling a JavaFX 2 button with FXML only - How to add an image to a button?

The graphics tag prompted the idea to do it like this:



<TableView>
    <placeholder><Label text="Some Text"></Label></placeholder>
</TableView>

      

And luckily it works! Hope I helped some of you too. Also, it's a shame I asked this question too quickly.

+2


source







All Articles