
org.datafx.control.cell.ActionTableCell Maven / Gradle / Ivy
The newest version!
package org.datafx.control.cell;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonBase;
import javafx.scene.control.Hyperlink;
import javafx.scene.control.TableCell;
import java.util.function.Consumer;
public class ActionTableCell extends TableCell {
private Consumer consumer;
private U button;
public ActionTableCell(Consumer consumer, U button) {
this.consumer = consumer;
this.button = button;
button.setOnAction((e) -> consumer.accept((S) getTableRow().getItem()));
setAlignment(Pos.CENTER);
}
@Override
protected void updateItem(T item, boolean empty) {
if(empty) {
setGraphic(null);
} else {
setGraphic(button);
}
}
public static ActionTableCell createWithButton(Consumer consumer, String text) {
return new ActionTableCell(consumer, new Button(text));
}
public static ActionTableCell createWithHyperlink(Consumer consumer, String text) {
return new ActionTableCell(consumer, new Hyperlink(text));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy