e930. copying cell values to the clipboard from a jtable component.txt

来自「这里面包含了一百多个JAVA源文件」· 文本 代码 · 共 39 行

TXT
39
字号
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 + =
减小字号Ctrl + -
显示快捷键?