删除空 javafx 表的默认“表中无内容”文本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24765549/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Remove the default 'no content in table' text for empty javafx table
提问by Japheth Ongeri - inkalimeva
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.
我想将空 javafx 表显示的默认文本删除或更改No content in table
为对用户更有意义的内容。
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
例如,在显示学生的表格中,当没有学生显示时,我希望它对课程表说“数据库中没有学生”或“学生没有课程”。我不知道这在 javafx 中是否可行,无论是通过 java 代码、使用场景构建器,还是通过在 IDE 中编辑 .fxml 文件。到目前为止,我已经查看了场景构建器中 tableview 的属性,但看不到此文本的相关属性
采纳答案by Brendan
You are correct in that the TableViewcontrol 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 propertywhich can be set to any object of type Node. For example...
您是正确的,因为TableView控件没有String
直接操作表为空时显示的文本的setter 方法。您要做的是使用 TableView 的占位符属性,该属性可以设置为Node类型的任何对象。例如...
myTableView.setPlaceholder(new Label("My table is empty message"));
回答by K. Gol
You can also do it from *.fxml file, by adding placeholder with empty label.
您也可以通过添加带有空标签的占位符从 *.fxml 文件中执行此操作。
<TableView>
<placeholder>
<Label text=""/>
</placeholder>
<columns>
<TableColumn text="Column1"/>
<TableColumn text="Column2"/>
</columns>
</TableView>