1
0
mirror of https://github.com/DanilaFe/abacus synced 2026-01-27 00:55:19 +00:00

Implement a cell that copies input when clicked, and add it to table.

This commit is contained in:
2017-07-31 22:53:42 -07:00
parent 0b97a935bf
commit 05d0755526
2 changed files with 35 additions and 4 deletions

View File

@@ -0,0 +1,26 @@
package org.nwapw.abacus.fx;
import javafx.scene.control.TableCell;
import javafx.scene.input.MouseEvent;
import java.awt.*;
import java.awt.datatransfer.StringSelection;
public class CopyableCell<S, T> extends TableCell<S, T> {
public CopyableCell(){
addEventFilter(MouseEvent.MOUSE_CLICKED, event -> {
if(event.getClickCount() == 2){
Toolkit.getDefaultToolkit().getSystemClipboard()
.setContents(new StringSelection(getText()), null);
}
});
}
@Override
protected void updateItem(T item, boolean empty) {
super.updateItem(item, empty);
setText((empty || item == null) ? null : item.toString());
setGraphic(null);
}
}