📄 e930. copying cell values to the clipboard from a jtable component.txt
字号:
Given 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"});
Related Examples
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -