Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set placeholder of JavaFX TableView in FXML

I know the following problem is a bit of a luxury problem:

I would like to keep the initialize of my FXML Controller as clean as possible, and therefore I would like to set the placeholder of my TableView in the FXML file (as I think it is the best place to keep 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 does not work, because the placeholder property expects a Node. That is why I set the placeholder like this in the initialize of the FXML controller:

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

This works, but as I said, I would like to manage this from the FXML file only. Some my question is:

How can I set the placeholder from within the FXML file?

Note: please let me know if this i even possible, because when it is not, I will fill a feature request (with a low priority of course!).

like image 870
bashoogzaad Avatar asked Dec 09 '14 09:12

bashoogzaad


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.

like image 179
eckig Avatar answered Oct 28 '22 06:10

eckig


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

The graphic tag triggered the idea to do it like this:

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

And luckily it works! I hope I helped some of you too. Also, sorry for asking this question too quickly.

like image 35
bashoogzaad Avatar answered Oct 28 '22 06:10

bashoogzaad