在做了关于TableView的Oracle教程之后,我想知道是否有一种方法可以以编程方式将不同的CSS样式应用于所选的TableView行.例如,用户选择某一行,单击"突出显示"按钮,所选行获得棕色背景,白色文本填充等.我在JavaFX中阅读了JavaFX tableview颜色,用2种颜色更新TableView行外观和背景?,但无济于事= /
这是来源:
import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.stage.Stage;
public class TableViewSample extends Application {
private TableView<Person> table = new TableView<Person>();
private final ObservableList<Person> data =
FXCollections.observableArrayList(
new Person("Jacob", "Smith", "jacob.smith@example.com"),
new Person("Isabella", "Johnson", "isabella.johnson@example.com"),
new Person("Ethan", "Williams", …
Run Code Online (Sandbox Code Playgroud) 在JavaFX 2中,使用CSS,是否可以创建2种颜色的背景?想象一下,例如TableCell
高度为10像素.我希望前2 px(垂直)为红色,其余8 px(垂直)应保持默认背景颜色.在JavaFX 2中使用CSS是否可行?怎么样?
例:
原始背景:
期望的结果:
(上面的2个像素被红色代替)
感谢您对此的任何暗示!
有没有办法让TableCell水平跨度?我想在JavaFX 2.2中创建一个类似于附图所示的tableview
示例http://cache.fxexperience.com/wp-content/uploads/2012/10/Picture2.png
顺便说一句,图像来自这个功能的样本,但它特定于Java FX 8.0.我一直在尝试使用rowFactory但是没有足够的文档来说明如何使用它.
提前致谢.
我有一个tableView,其中有很多项目,在某些项目中,我需要将前景色设置为红色。因此它是动态设置的。我成功完成的工作是向表中添加rowFactory并通过CSS更改了背景颜色,但是前景没有改变。总是黑色的:
tableViewAbastecidas.setRowFactory(param -> new TableRow<LeituraPista>() {
@Override
protected void updateItem(LeituraPista item, boolean empty) {
if (item == null) {
return;
}
String estilo;
if (tableViewAbastecidas.getSelectionModel().getSelectedItems().contains(item)) {
estilo = "-fx-background-color: linear-gradient(#95caff 0%, #77acff 90%, #e0e0e0 90%);";
} else {
estilo = "-fx-background-color: linear-gradient(white 0%, white 90%, #e0e0e0 90%);";
}
if (myConditionIsTrue) {
estilo += "-fx-fill: #ff0000;-fx-text-fill: chartreuse;"; //Doesn't work, always black
}
setStyle(estilo);
}
});
Run Code Online (Sandbox Code Playgroud)