Remove the default 'no content in table' text for empty javafx table

JavaJavafxJavafx 8FxmlScenebuilder

Java Problem Overview


I would like to remove or change the default text shown by an empty javafx table from No content in table to something more meaningful for the user.

For example in a table showing students, when there are no students to show I want it to say "No students in database" or "Student has no courses" for a courses table. I don't know if this is possible in javafx, either through java code, using scene builder, or by editing the .fxml file in an IDE. So far I have looked at the properties of the tableview in scene builder and I can't see a related property for this text

Java Solutions


Solution 1 - Java

You are correct in that the TableView control does not have a String setter method that directly manipulates the text shown when the table is empty. What you will want to do instead is use the TableView's placeholder property which can be set to any object of type Node. For example...

myTableView.setPlaceholder(new Label("My table is empty message"));

Solution 2 - Java

You can also do it from *.fxml file, by adding placeholder with empty label.

<TableView>
    <placeholder>
        <Label text=""/>
    </placeholder>
    <columns>
        <TableColumn text="Column1"/>
        <TableColumn text="Column2"/>
    </columns>
</TableView>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJapheth Ongeri - inkalimevaView Question on Stackoverflow
Solution 1 - JavaBrendanView Answer on Stackoverflow
Solution 2 - JavaK. GolView Answer on Stackoverflow