我有这个常见问题,因为它似乎是.重置后,我的表视图不会刷新我的项目.我检查了数据,这是新的数据.
我从互联网尝试了多种解决方案但没有成功.
无法重置所有列,因为它添加了一个空的额外(不知道原因)和调整大小只是破坏.
我的表格不可编辑.新数据已更改.
如果我更改项目的顺序并且行更改(:|),则刷新数据.
我只是没有想法.
目前刷新代码非常简单.
ObservableList<User> data = FXCollections.observableArrayList(User.getResellers());
reseller_table.setItems(data);
Run Code Online (Sandbox Code Playgroud)
新数据再次正确.当我选择tableView时,它返回新的正确Item.
在做了关于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)