I have a JTable where the cells are not editable. How do I allow their contents to be selected and copied without making the Table editable?

Sandip Chitale

The cell selection is not dependant on the editability of the JTable (which is really controlled by the TableModel behind it). The selection is controlled by the "selectionMode" property and installed SelectionModel.

Assuming that when you say copy you mean copy to the clipboard - you need to walk through all the selected cells, get the values for each cell, build a comma (or tab) separated list of values into a StringBuffer. Then copy that StringBuffer.toString() to clipboard using

import java.awt.*;
import java.awt.datatransfer.*;
Toolkit tk = Toolkit.getDefaultTOolkit();
Clipboard sysCb = tk.getSystemClipboard(...);
sysCb.setContent(new StringSelection(stringBuffer.toString()));

0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact