![]() |
The Java Developers Almanac 1.4 |
|
e930. Copying Cell Values to the Clipboard from a JTable ComponentGiven the cell values in the example code below, typing control-c in a table component while all cells have been selected causes the following text to be copied to the clipboard. In particular, the cell values are formatted as an HTML table.Note: Control-c only works if the selected cells do not contain a null value. <html>
<table>
<tr>
<th id=0>A
<th id=1>B
<th id=2>C
<tr id=0>
<td>A1
<td>B1
<td>C1
<tr id=1>
<td>A2
<td>B2
<td>C2
<tr id=2>
<td>A3
<td>B3
<td>C3
</table>
</html>
Here is the example code with initial cell values.
JTable table = new JTable();
// Add data
DefaultTableModel model = (DefaultTableModel)table.getModel();
model.addColumn("A");
model.addColumn("B");
model.addColumn("C");
model.addRow(new Object[]{"A1", "B1", "C1"});
model.addRow(new Object[]{"A2", "B2", "C2"});
model.addRow(new Object[]{"A3", "B3", "C3"});
e927. Using Built-In Cell Renderers and Editors in a JTable Component e928. Creating a Custom Cell Renderer in a JTable Component e929. Creating a Class-Based Custom Cell Renderer in a JTable Component
© 2002 Addison-Wesley. |