Allow user to copy data from TableView

随声附和 提交于 2019-12-04 06:29:57

I recommended that you review this post, work for me

http://respostas.guj.com.br/47439-habilitar-copypaste-tableview-funcionando-duvida-editar-funcionalidade

The author use an aditional util java class for enable the cell content copy from a tableView

You just have to create a listener in the scene, something like:

scene.getAccelerators()
.put(new KeyCodeCombination(KeyCode.C, KeyCombination.CONTROL_ANY), new Runnable() {
    @Override
    public void run() {
        int row = table.getSelectionModel().getSelectedIndex();
        DataRow tmp = table.getItems().get(row);
        final Clipboard clipboard = Clipboard.getSystemClipboard();
        final ClipboardContent content = new ClipboardContent();
        if(table.getSelectionModel().isSelected(row, numColumn)){
            System.out.println(tmp.getNumSlices());
            content.putString(tmp.getNumSlices().toString());
        }
        else{
            System.out.println(tmp.getSelected());
            content.putString(tmp.getSelected());
        }
        clipboard.setContent(content);
    }
});

For a complete example, you can download it at the gist.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!