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:
26
src/main/java/org/nwapw/abacus/fx/CopyableCell.java
Normal file
26
src/main/java/org/nwapw/abacus/fx/CopyableCell.java
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user