5

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!).

bashoogzaad
  • 4,611
  • 8
  • 40
  • 65

2 Answers2

15

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.

eckig
  • 10,964
  • 4
  • 38
  • 52
  • Thank you for answering so quickly. Although, it is the same as I already found, of course I will give you all the credits! – bashoogzaad Dec 09 '14 at 09:44
2

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.

Community
  • 1
  • 1
bashoogzaad
  • 4,611
  • 8
  • 40
  • 65