- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有以下回调监听 TableView 的选定单元格:
Callback<TableColumn<MyFTPFile,String>, TableCell<MyFTPFile,String>> cellFactory =
new Callback<TableColumn<MyFTPFile,String>, TableCell<MyFTPFile,String>>() {
public TableCell<MyFTPFile,String> call(TableColumn<MyFTPFile,String> p) {
TableCell<MyFTPFile,String> cell = new TableCell<MyFTPFile, String>() {
@Override
public void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
setText(empty ? null : getString());
setGraphic(null);
}
private String getString() {
return getItem() == null ? "" : getItem().toString();
}
};
cell.addEventFilter(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
if (event.getClickCount() > 1) {
TableCell<MyFTPFile,String> c = (TableCell<MyFTPFile,String>) event.getSource();
ftpObservablelist = MyFTPClient.getInstance().getFtpObservableList();
ftpTable.setItems(ftpObservablelist);
}
}
});
最佳答案
MyFTPFile 对象与单元格的行相关联,因此,正如提问者在他的评论中指出的那样,它可以通过 cell.getTableRow().getItem()
检索。 .
起初我以为这应该是cell.getItem() ,它返回与单元格关联的数据值。但是,大多数情况下,单元格数据值将是支持项的属性而不是对象本身(例如 MyFTPFile 对象的文件名字段)。
好奇的可执行示例:
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.control.cell.TextFieldTableCell;
import javafx.scene.input.MouseEvent;
import javafx.stage.Stage;
import javafx.util.Callback;
public class TableClickListener extends Application {
public static void main(String[] args) {
launch(args);
}
class FTPTableCell<S, T> extends TextFieldTableCell<S, T> {
FTPTableCell() {
super();
addEventFilter(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
if (event.getClickCount() > 1 && getItem() != null) {
System.out.println("Sending " + getTableRow().getItem() + " to the FTP client");
}
}
});
}
}
final Callback<TableColumn<MyFTPFile, String>, TableCell<MyFTPFile, String>> FTP_TABLE_CELL_FACTORY =
new Callback<TableColumn<MyFTPFile, String>, TableCell<MyFTPFile, String>>() {
public TableCell<MyFTPFile, String> call(TableColumn<MyFTPFile, String> p) {
return new FTPTableCell<>();
}
};
@Override
public void start(final Stage stage) {
final TableView<MyFTPFile> table = new TableView<>();
final TableColumn<MyFTPFile, String> filenameColumn = new TableColumn<>("Filename");
filenameColumn.setCellValueFactory(new PropertyValueFactory<MyFTPFile, String>("filename"));
filenameColumn.setCellFactory(FTP_TABLE_CELL_FACTORY);
filenameColumn.setMinWidth(150);
final TableColumn<MyFTPFile, String> ratingColumn = new TableColumn<>("Rating");
ratingColumn.setCellValueFactory(new PropertyValueFactory<MyFTPFile, String>("rating"));
ratingColumn.setCellFactory(FTP_TABLE_CELL_FACTORY);
ratingColumn.setMinWidth(20);
table.getColumns().setAll(filenameColumn, ratingColumn);
table.getItems().setAll(
new MyFTPFile("xyzzy.txt", 10),
new MyFTPFile("management_report.doc", 1),
new MyFTPFile("flower.png", 7)
);
table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
stage.setScene(new Scene(new Group(table)));
stage.show();
}
public class MyFTPFile {
private final String filename;
private final int rating;
MyFTPFile(String filename, int rating) {
this.filename = filename;
this.rating = rating;
}
public String getFilename() {
return filename;
}
public int getRating() {
return rating;
}
@Override
public String toString() {
return "MyFTPFile{" +
"filename='" + filename + '\'' +
", rating=" + rating +
'}';
}
}
}
关于javafx-2 - Javafx,获取一个TableCell引用的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13585164/
我有一个包含单元格的 TableView。我的表格的工作方式类似于坐标系,而不是像通常的表格。 Click here for more about this. 现在,我需要将一个单元格拖放到另一个单元
我目前正在开发一个应用程序,其中使用 TableView,其中包含一个 TableCell 中的 RadioButton。为此,我创建了一个自己的 RadioButtonCell 类。我还有一个“添加
我在 tableviewcell(原型(prototype)单元格)内添加了一个标签,并使用 Storyboard对标签应用了以下约束: 50 领先利润率 50 尾随 margin 20 上边距 20
我需要放入一个表格单元格、一个标签和进度条。 对于进度条,我使用的是: @FXML private TableView tableView; @FXML private TableColumn col
我对表格单元格中的分段控件有疑问。分段控制无 Action segmentedFilter.addTarget(self, action: #selector(ProductListFilterCel
我需要你的帮助! 我有一个表格,里面有行(姓名等)现在,当位于该行上的对象具有特定值时,我想为特定的 tableCells 背景着色。但我只得到它来读取这个单元格的值。但我需要阅读对象(在我的代码中称
JavaFX:如何使用自定义样式表将文本颜色应用于 TableCell? 当我直接在我的 CellFactory 中使用 setTextFill() 时它工作正常,但我想使用外部 CSS 文件应用自定
我想从 TableCell 中的模型获取一个属性,这样我就可以根据该属性来操纵单元格,让我们看一下以下示例: 我有一个像这样的模型: public class Model { private
我的应用程序有一个 TableView,其中填充了对图像文件的引用列表。 数据从数据库加载,仅提供有关如何定位图像文件本身的信息(因此它指示图像的子文件夹和文件名)。 在我的 TableView 中,
如何确定 javafx 表单元格引用的数据类型(字符串、整数、 double 等)。例如。我有一个自定义单元工厂,它被分配给 Javafx Controller 中的一个字段,如下所示: Custom
这不是一个特定于语言的问题,但我需要它来玩 java 游戏。我有一个尺寸为 3x3 的表(二维数组)。所以单元格的一维索引是: 1 2 3 4 5 6 7 8 9 当有这个索引时,我想从中获取二维索引
例如,当您按下 Enter 键时,TextFieldTableCell 会响应并调用 commitEdit()。 如果我使用自定义节点来显示,那么我如何监听确认编辑的方法?例如,我有一个 DateTi
我正在尝试将 tableCell 添加到 TableView 中的适当部分。我有一个按如下方式索引的客户端列表: var clients = Client.loadAllClients()
Xcode: swift 完全错误: 无法找到接受 caseImage 类型的参数列表的类型 TableCell 的初始值设定项:(UIImge, caseName: String, caseDate
我最近遇到了一个有趣的tutorial在 Ray Wenderlich 的网站上,了解如何通过使用长按手势并拖动 TableCell 来重新定位 TableCell,以更改顺序。一切正常,但我相信它会
我创建了一个自定义 tableCell 当我通过 backgroundView 将 xib 连接到文件所有者时,我成功地让项目出现在我的表中。问题是我无法选择一行并获得返回。 如果我取消选择 back
我正在尝试使用 segue 将注释传递给 mapkit 但是当我测试它时总是以 fatal error 结束:在展开可选值时意外发现 nil annotation is not a nil obj b
我的代码如下。我想在 tableCell() 中的单元格之间添加空间相当于的东西 我不是在寻找 cellpadding 或 cellspacing,因为它们都在左单元格边框和
我必须根据显示的数据更改 TableCell 的样式类,例如:如果两个连续行中的单元格值相同,则必须突出显示该单元格(即:背景红色)。这必须既能将数据添加到表中又能按任何列排序。 为此,在排序时,我向
我正在尝试在我的 TableView 中创建自定义 TableCell。我希望它显示一个 ComboBox,我可以在其中选择一个 String 值,然后显示 String 值,就好像它是用户输入一样。
我是一名优秀的程序员,十分优秀!