设置JavaFX TableView Cells的字体颜色?
在我的 Java 桌面应用程序中,我有一个包含 3 列的 JavaFX 表。我想将第三列的字体颜色设置为红色。我根本无法设置 Tableb 的字体颜色。我查看了 CSS,但没有发现任何东西。有没有办法用 CSS 来做到这一点?我还寻找了 setFont(),希望能这样设置。那里什么也没有。我什至无法找到在某个单元格上设置某些内容的方法。
TableView<TableData> myTable = new TableView<TableData>();
ObservableList<TableData> myTableData = FXCollections.observableArreyList(
new TableData("data", "data", "data"),
new TableData("data", "data", "data"));
TableColumn firstColumn = new TableColumn("First Column");
firstColumn.setProperty("one");
TableColumn secondColumn = new TableColumn("Second Column");
secondColumn .setProperty("two");
TableColumn thirdColumn = new TableColumn("Third Column");
thirdColumn .setProperty("three");
myTable.setItems(myTableData);
myTable.getColumns.addAll(firstColumn, secondColumn, thirdColumn);
我怎样才能做到这一点?如何设置字体颜色?任何帮助将不胜感激。
In my Java Desktop Application I have a JavaFX Table with 3 columns. I want to set the font color of the 3rd column to red. I have not been able to set the font color of the Tableb at all. I looked into CSS and I did not find anything. Is there a way to do it with CSS? I also looked for setFont() with the hope of setting it that way. Nothing there. I could not even figure a way to set something on a certain cell.
TableView<TableData> myTable = new TableView<TableData>();
ObservableList<TableData> myTableData = FXCollections.observableArreyList(
new TableData("data", "data", "data"),
new TableData("data", "data", "data"));
TableColumn firstColumn = new TableColumn("First Column");
firstColumn.setProperty("one");
TableColumn secondColumn = new TableColumn("Second Column");
secondColumn .setProperty("two");
TableColumn thirdColumn = new TableColumn("Third Column");
thirdColumn .setProperty("three");
myTable.setItems(myTableData);
myTable.getColumns.addAll(firstColumn, secondColumn, thirdColumn);
How can I accomplish this? How can I set to font color? Any help will be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您需要重写 CellFactory。
仅第三列的部分代码:
整个代码示例:
You need to override the CellFactory.
Partial code just of the third column:
Entire Code Example:
我找到了CSS代码。将此
red-column
类应用到您的列中。你的桌子将会是这样的。
表视图的完整 css 是 此处。
I found a CSS code. Apply this
red-column
class into your column.Your table will be like this.
Full css for table-view is here.
代码需要稍加修改:
The Code need to be little changed:
或者,类似于 Panduka,
Or, similar to Panduka,
对于多行单元格:
For a multiline cell :